ProjectDetailResource.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Http\Resources\API;
  3. use App\Models\User;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Http\Resources\Json\JsonResource;
  6. class ProjectDetailResource 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. // $assets = [];
  16. // foreach ($this->assets as $asset){
  17. // $assets[] = new SimpleAssetResource($asset);
  18. // $assetIds[] = $asset->id;
  19. // }
  20. // $plans = [];
  21. // foreach ($this->plans as $plan){
  22. // $plans[] = new SimplePlanResource($plan);
  23. // $plansIds[] = $plan['id'];
  24. // }
  25. $whitelist=make_array_list($this->whitelist??'');
  26. $whitelistName=User::query()->whereIn('id',$whitelist)->get();
  27. return [
  28. 'id' => $this->id,
  29. 'name' => $this->name,
  30. 'code' => $this->code,
  31. 'status' => $this->status,
  32. 'const' => $this->const,
  33. 'begin' => $this->begin,
  34. 'end' => $this->end,
  35. //'available_days' => $this->available_days,
  36. 'latitude' => $this->latitude,
  37. 'longitude' => $this->longitude,
  38. 'type' => $this->type,
  39. 'acl' => $this->acl,
  40. 'assets' =>SimpleAssetResource::collection($this->assets),
  41. 'plans' =>SimplePlanResource::collection($this->plans),
  42. 'approval_status'=>$this->approval_status,
  43. "whitelist" => $whitelist,
  44. "whitelist_name"=>$whitelistName,
  45. 'description' => $this->description?(new \App\Services\File\ImageUrlService)->getImageUrl($this->description):null,
  46. 'requirement_total'=>$this->requirements->count(),
  47. 'task_total'=>$this->tasks->count(),
  48. "cost_unit"=>$this->cost_unit,
  49. ];
  50. }
  51. }