SubCategoryCollection.php 765 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace App\Http\Resources\V2;
  3. use Illuminate\Http\Resources\Json\ResourceCollection;
  4. class SubCategoryCollection extends ResourceCollection
  5. {
  6. public function toArray($request)
  7. {
  8. return [
  9. 'data' => $this->collection->map(function($data) {
  10. return [
  11. 'name' => $data->name,
  12. 'subSubCategories' => new SubSubCategoryCollection($data->subSubCategories),
  13. 'links' => [
  14. 'products' => route('products.subCategory', $data->id)
  15. ]
  16. ];
  17. })
  18. ];
  19. }
  20. public function with($request)
  21. {
  22. return [
  23. 'success' => true,
  24. 'status' => 200
  25. ];
  26. }
  27. }