瀏覽代碼

add project / asset info

kevinlan@lpchku.com 5 月之前
父節點
當前提交
db736456a0
共有 1 個文件被更改,包括 13 次插入0 次删除
  1. 13 0
      app/Http/Resources/API/ContainerDetailResource.php

+ 13 - 0
app/Http/Resources/API/ContainerDetailResource.php

@@ -2,6 +2,9 @@
 
 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;
@@ -20,6 +23,14 @@ class ContainerDetailResource extends JsonResource
         $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,
@@ -39,6 +50,8 @@ class ContainerDetailResource extends JsonResource
             "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] : [],
+            'asset' => isset($asset) ? ['id' => $asset?->id ,'name' => $asset?->name] : [],
         ];
     }
 }