123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace App\Http\Resources\API;
- use App\Models\Asset;
- use App\Models\Library;
- use App\Models\Project;
- use App\Models\User;
- use Illuminate\Http\Request;
- use Illuminate\Http\Resources\Json\JsonResource;
- class ContainerDetailResource extends JsonResource
- {
- /**
- * Transform the resource into an array.
- *
- * @return array<string, mixed>
- */
- 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,
- ];
- }
- }
|