ProjectResource.php 865 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace App\Http\Resources\API;
  3. use App\Models\ProjectAsset;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Http\Resources\Json\JsonResource;
  6. class ProjectResource extends JsonResource
  7. {
  8. /**
  9. * Transform the resource into an array.
  10. *
  11. * @return array<string, mixed>
  12. */
  13. public function toArray(Request $request): array
  14. {
  15. $project_ids = ProjectAsset::select('project_id')->distinct()->pluck('project_id')->all();
  16. return [
  17. 'id' => $this->id,
  18. 'name' => $this->name,
  19. 'code' => $this->code,
  20. 'status' => $this->status,
  21. 'const' => $this->const,
  22. 'begin' => $this->begin,
  23. 'end' => $this->end,
  24. 'has_asset' =>in_array($this->id,$project_ids),
  25. //'asset' => new AssetParentResource($this->asset),
  26. ];
  27. }
  28. }