*/ public function toArray(Request $request): array { $project_ids = ProjectAsset::select('project_id')->distinct()->pluck('project_id')->all(); return [ 'id' => $this->id, 'name' => $this->name, 'code' => $this->code, 'status' => $this->status, 'const' => $this->const, 'begin' => $this->begin, 'end' => $this->end, 'has_asset' =>in_array($this->id,$project_ids), 'asset'=> $this->when($this->assets->isNotEmpty(),function (){ return $this->assets->map(function ($asset){ return new SimpleAssetResource($asset); })->all(); }), //'asset' => new AssetParentResource($this->asset), ]; } }