AssetResource.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Http\Resources\API;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Http\Resources\Json\JsonResource;
  5. class AssetResource extends JsonResource
  6. {
  7. /**
  8. * Transform the resource into an array.
  9. *
  10. * @return array<string, mixed>
  11. */
  12. public function toArray(Request $request): array
  13. {
  14. return [
  15. 'id' => $this->id,
  16. 'name' => $this->name,
  17. 'code' => $this->code,
  18. 'description' => $this->description,
  19. 'status' => $this->status,
  20. 'created_by' => $this->created_by,
  21. 'owner' => $this->owner,
  22. 'address' => $this->address,
  23. 'group_id' => $this->group_id ?? 0,
  24. 'geo_address_code' => $this->geo_address_code,
  25. 'acl' => $this->acl,
  26. 'whitelist' => $this->whitelist,
  27. 'latitude' => $this->latitude,
  28. 'longitude' => $this->longitude,
  29. 'parent_id' => $this->parent_id,
  30. 'level' => count(explode(",", trim($this->path, ","))),
  31. 'requirement_total' => $this->total_requirements_count,
  32. 'plan_total' => $this->total_plans_count,
  33. 'created_at'=> $this->created_at,
  34. 'equity_interest'=>$this->equity_interest,
  35. 'developer' =>$this->developer,
  36. 'date_completed' =>$this->date_completed,
  37. 'total_floor_area' => $this->total_floor_area,
  38. 'contact_person'=>$this->contact_person,
  39. 'contact_phone'=>$this->contact_phone,
  40. 'contact_email'=>$this->contact_email,
  41. 'property'=> $this->property,
  42. 'building_type_description'=>$this->building_type_description,
  43. 'children' => $this->when($this->children->isNotEmpty(), function () {
  44. return $this->children->map(function ($child) {
  45. return new AssetResource($child, $this->level);
  46. })->all();
  47. }),
  48. ];
  49. }
  50. }