ProjectSimpleResource.php 791 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace App\Http\Resources\API;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Http\Resources\Json\JsonResource;
  5. class ProjectSimpleResource extends JsonResource
  6. {
  7. /**
  8. * Transform the resource into an array.
  9. *
  10. * @return array<string, mixed>
  11. */
  12. public function toArray(Request $request): array
  13. {
  14. return [
  15. 'id' => $this->id,
  16. 'name' => $this->name,
  17. 'display_id'=>$this->display_id,
  18. 'begin' => $this->begin,
  19. 'end' => $this->end,
  20. 'asset'=> $this->when($this->assets->isNotEmpty(),function (){
  21. return $this->assets->map(function ($asset){
  22. return new SimpleAssetResource($asset);
  23. })->all();
  24. }),
  25. ];
  26. }
  27. }