lcly-data-admin/app/Http/Resources/CropFlowResource.php

33 lines
963 B
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class CropFlowResource 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,
'flow_name' => $this->flow_name,
'crop_name' => $this->whenLoaded('crop', function (){
return $this->crop?->name;
}, ''),
'crop_id' => $this->crop_id,
'time_year' => $this->time_year,
'sale' => $this->sale,
'created_by' => $this->whenLoaded('createdBy', function (){
return $this->createdBy?->name;
}, ''),//录入人
'created_at' => strtotime($this->created_at) ?? 0,//录入时间
];
}
}