*/ public function toArray(Request $request): array { $content = $this->content($request->get("version", 0))->first(); $whitelist=make_array_list($this->whitelist??''); $whitelistName=User::query()->whereIn('id',$whitelist)->get(); $mailto=$this->mailto; $mailtoName=User::query()->whereIn('id',$mailto)->get(); // $library = Library::query()->where('id',$this->library_id)->first(); if ($this->library->type == 'project'){ $project = Project::query()->where('id',$this->library->project_id)->first(); }else if($this->library->type == 'asset'){ $asset = Asset::query()->where('id',$this->library->asset_id)->first(); } return [ 'id' => $this->id, 'name' => $content?->name, 'library' => new LibrarySimpleResource($this->library), 'naming_rule' => new NamingRuleSimpleResource($this->namingRule), 'naming_rules' => $this->naming_rules, "mailto" => $mailto, "mailto_name" =>UserProfileResource::collection($mailtoName), "email_subject" => $this->email_subject, "doc_stage" => $this->doc_stage, "doc_type" => $this->doc_type, "description" => $content?->description ? (new \App\Services\File\ImageUrlService)->getImageUrl($content?->description) : "", "acl" => $this->acl, "whitelist" =>$whitelist, "whitelist_name"=>UserProfileResource::collection($whitelistName), "version" => $this->version, "created_at" => (string)$this->created_at, "created_by" => new UserProfileResource($this->createdBy), 'approval_status'=>$this->approval_status, 'project' => isset($project) ? ['id' => $project?->id ,'name' => $project?->name] : null, 'asset' => isset($asset) ? ['id' => $asset?->id ,'name' => $asset?->name] : null, ]; } }