123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace App\Http\Resources\API;
- use App\Models\User;
- use Illuminate\Http\Request;
- use Illuminate\Http\Resources\Json\JsonResource;
- class ProjectDetailResource extends JsonResource
- {
- /**
- * Transform the resource into an array.
- *
- * @return array<string, mixed>
- */
- public function toArray(Request $request): array
- {
- // $assets = [];
- // foreach ($this->assets as $asset){
- // $assets[] = new SimpleAssetResource($asset);
- // $assetIds[] = $asset->id;
- // }
- // $plans = [];
- // foreach ($this->plans as $plan){
- // $plans[] = new SimplePlanResource($plan);
- // $plansIds[] = $plan['id'];
- // }
- $whitelist=make_array_list($this->whitelist??'');
- $whitelistName=User::query()->whereIn('id',$whitelist)->get();
- return [
- 'id' => $this->id,
- 'name' => $this->name,
- 'code' => $this->code,
- 'status' => $this->status,
- 'const' => $this->const,
- 'begin' => $this->begin,
- 'end' => $this->end,
- //'available_days' => $this->available_days,
- 'latitude' => $this->latitude,
- 'longitude' => $this->longitude,
- 'type' => $this->type,
- 'acl' => $this->acl,
- 'assets' =>SimpleAssetResource::collection($this->assets),
- 'plans' =>SimplePlanResource::collection($this->plans),
- 'approval_status'=>$this->approval_status,
- "whitelist" => $whitelist,
- "whitelist_name"=>$whitelistName,
- 'description' => $this->description?(new \App\Services\File\ImageUrlService)->getImageUrl($this->description):null,
- 'requirement_total'=>$this->requirements->count(),
- 'task_total'=>$this->tasks->count(),
- "cost_unit"=>$this->cost_unit,
- ];
- }
- }
|