TaskResource.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Http\Resources\API;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Http\Resources\Json\JsonResource;
  5. class TaskResource 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. "parent_id" => $this->parent_id,
  18. "begin" => $this->begin,
  19. "end" => $this->end,
  20. "status" => $this->status,
  21. 'approval_status' => $this->approval_status,
  22. "assign_to" => new UserProfileResource($this->assignTo),
  23. "created_by" => new UserProfileResource($this->createdBy),
  24. //"children" => TaskResource::collection($this->children),
  25. 'display_id'=>$this->display_id,
  26. 'children' => $this->when($this->children->isNotEmpty(),function (){
  27. return $this->children->map(function ($child){
  28. return new TaskResource($child);
  29. })->all();
  30. }),
  31. 'created_at'=>(string)$this->created_at,
  32. 'belong_project' =>new ProjectSimpleResource($this->project),
  33. ];
  34. }
  35. }