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

32 lines
996 B
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
use Peidikeji\Keywords\Http\Resources\KeywordResource;
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 ?? '',
'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,
'crops' => KeywordResource::collection($this->whenLoaded('crops'))
];
}
}