37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class DeviceResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'type' => $this->type?->typeName() ?? '未知',
|
|
'sn' => $this->sn,
|
|
'base_name' => $this->whenLoaded('base', function () {
|
|
return $this->base?->name ?? '';
|
|
}, ''),
|
|
'base_id' => $this->agricultural_base_id,
|
|
'monitoring_point' => $this->monitoring_point ?? '',
|
|
'status' => $this->status?->value,
|
|
'extends' => $this->extends ?? [],
|
|
'created_by' => $this->whenLoaded('createdBy', function () {
|
|
return $this->createdBy?->name;
|
|
}, ''), //录入人
|
|
'created_at' => strtotime($this->created_at) ?? 0, //录入时间
|
|
'is_recommend' => $this->is_recommend,
|
|
'sort' => $this->sort,
|
|
];
|
|
}
|
|
}
|