40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class CropYieldResource 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,
|
|
'base_name' => $this->whenLoaded('base', function () {
|
|
return $this->base?->name;
|
|
}, ''),
|
|
'base_id' => $this->base_id,
|
|
'crop_name' => $this->whenLoaded('crop', function () {
|
|
return $this->crop?->name;
|
|
}, ''),
|
|
'crop_id' => $this->crop_id,
|
|
'time_year' => $this->time_year,
|
|
'quarter' => $this->quarter,
|
|
'yield' => $this->yield,
|
|
'output' => $this->output,
|
|
'cultivated' => $this->cultivated,
|
|
'extends' => $this->extends,
|
|
'created_by' => $this->whenLoaded('createdBy', function () {
|
|
return $this->createdBy?->name;
|
|
}, ''), //录入人
|
|
'created_at' => strtotime($this->created_at) ?? 0, //录入时间
|
|
];
|
|
}
|
|
}
|