RequirementGroupResource.php 750 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace App\Http\Resources\API;
  3. use App\Models\RequirementGroup;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Http\Resources\Json\JsonResource;
  6. class RequirementGroupResource 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. //return parent::toArray($request);
  16. return[
  17. 'id'=>$this->id,
  18. 'name'=>$this->name,
  19. 'asset_id'=>$this->asset_id,
  20. 'abbr_name'=>$this->abbr_name,
  21. 'parent_id' => $this->parent_id,
  22. 'children' =>$this->parent_id == 0 ? RequirementGroupResource::collection($this->children) : [],
  23. ];
  24. }
  25. }