*/ public function toArray(Request $request): array { return [ 'id' => $this->id, 'title' => $this->title, 'asset_id' => $this->asset_id, 'asset_name' => $this->asset ? $this->asset->name : null, 'parent_id' => $this->parent_id, 'requirement_total' => $this->requirements()->count(), 'project_total' => $this->projects()->count(), 'begin' => $this->begin, 'end' => $this->end, 'description' => $this->description?(new \App\Services\File\ImageUrlService)->getImageUrl($this->description):null, //'children' => $this->parent_id == 0 ? PlanResource::collection($this->children) : [], 'children' => $this->when($this->children->isNotEmpty(),function (){ return $this->children->map(function ($child){ return new PlanResource($child); })->all(); }), 'asset' => new AssetParentResource($this->asset), 'created_at'=>(string)$this->created_at, ]; } }