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

37 lines
1.3 KiB
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class AgriculturalBaseResource 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,
'name' => $this->name,
'address' => $this->address ?? '',
'person' => $this->person ?? '',
'address_lat' => $this->address_lat ?? '',
'address_lng' => $this->address_lng ?? '',
'description' => $this->description ?? '',
'map' => $this->map ?? '',
'areas' => ($this->areas ?? 0.00), //占地面积
'workforce' => $this->workforce ?? 0, //人数
'cultivated' => $this->cultivated ?? 0, //种养殖面积
'crops' => CropResource::collection($this->whenLoaded('crops')),
'devices' => DeviceResource::collection($this->whenLoaded('devices')),
'parent_id' => $this->parent_id ?? 0,
'sort' => $this->sort ?? 0,
'extends' => json_decode($this->extends ?? []),
];
}
}