AssetResource.php 2.3 KB

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