12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace App\Http\Resources\API;
- use App\Services\File\ImageUrlService;
- use Illuminate\Http\Request;
- use Illuminate\Http\Resources\Json\JsonResource;
- class AssetResource extends JsonResource
- {
- /**
- * Transform the resource into an array.
- *
- * @return array<string, mixed>
- */
- public function toArray(Request $request): array
- {
- return [
- 'id' => $this->id,
- 'name' => $this->name,
- 'code' => $this->code,
- 'description' => $this->description?(new \App\Services\File\ImageUrlService)->getImageUrl($this->description):null,
- 'status' => $this->status,
- 'created_by' => $this->created_by,
- 'owner' => $this->owner,
- 'address' => $this->address,
- 'group_id' => $this->group_id ?? 0,
- 'geo_address_code' => $this->geo_address_code,
- 'acl' => $this->acl,
- 'whitelist' => make_array_list($this->whitelist??''),
- 'latitude' => $this->latitude,
- 'longitude' => $this->longitude,
- 'parent_id' => $this->parent_id,
- 'parent_asset' => $this->when($this->parent !== null, function () {
- return[
- new AssetParentResource($this->parent)
- ];
- }),
- 'level' => count(explode(",", trim($this->path, ","))),
- 'requirement_total' => $this->total_requirements_count,
- 'plan_total' => $this->total_plans_count,
- 'created_at'=> $this->created_at,
- 'equity_interest'=>$this->equity_interest,
- 'developer' =>$this->developer,
- 'date_completed' =>$this->date_completed,
- 'total_floor_area' => $this->total_floor_area,
- 'contact_person'=>$this->contact_person,
- 'contact_phone'=>$this->contact_phone,
- 'contact_email'=>$this->contact_email,
- 'property'=> $this->property,
- 'building_type_description'=>$this->building_type_description,
- 'children' => $this->when($this->children->isNotEmpty(), function () {
- return $this->children->map(function ($child) {
- return new AssetResource($child, $this->level);
- })->all();
- }),
- ];
- }
- }
|