From bfcb01ba51086eb5528cb210ca930b3bda73da28 Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Fri, 18 Nov 2022 10:01:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=AD=A6=E6=8A=A5=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/DeviceWarningController.php | 2 +- app/Http/Resources/DeviceWarningResource.php | 9 +++++++++ app/Models/DeviceWarning.php | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/DeviceWarningController.php b/app/Http/Controllers/DeviceWarningController.php index a62786e..9c8e324 100644 --- a/app/Http/Controllers/DeviceWarningController.php +++ b/app/Http/Controllers/DeviceWarningController.php @@ -62,7 +62,7 @@ class DeviceWarningController extends Controller */ public function warningLog(Request $request) { - $query = DeviceWarning::filter($request->input())->orderBy('created_at', 'desc'); + $query = DeviceWarning::with(['base', 'device'])->filter($request->input())->orderBy('created_at', 'desc'); $list = $query->simplePaginate(Paginator::resolvePerPage('per_page', 20, 50)); return $this->json(DeviceWarningResource::collection($list)); diff --git a/app/Http/Resources/DeviceWarningResource.php b/app/Http/Resources/DeviceWarningResource.php index b811ca0..8353123 100644 --- a/app/Http/Resources/DeviceWarningResource.php +++ b/app/Http/Resources/DeviceWarningResource.php @@ -16,6 +16,15 @@ class DeviceWarningResource extends JsonResource { return [ 'id' => $this->id, + 'base_name' => $this->whenLoaded('base', function () { + return $this->base?->name ?? ''; + }, ''), + 'point_name' => $this->whenLoaded('device', function () { + return $this->device?->monitoring_point ?? ''; + }, ''), + 'device_type' => $this->whenLoaded('device', function () { + return $this->device?->type ?? 0; + }, ''), 'lv' => $this->lv, 'status' => $this->status, 'content' => $this->content, diff --git a/app/Models/DeviceWarning.php b/app/Models/DeviceWarning.php index e455f6d..3f29a6d 100644 --- a/app/Models/DeviceWarning.php +++ b/app/Models/DeviceWarning.php @@ -18,4 +18,8 @@ class DeviceWarning extends Model public function base(){ return $this->belongsTo(AgriculturalBase::class, 'base_id'); } + + public function device(){ + return $this->belongsTo(Device::class, 'device_id'); + } }