CategoryCollection.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Http\Resources\V2;
  3. use Illuminate\Http\Resources\Json\ResourceCollection;
  4. use App\Utility\CategoryUtility;
  5. class CategoryCollection extends ResourceCollection
  6. {
  7. public function toArray($request)
  8. {
  9. return [
  10. 'data' => $this->collection->map(function($data) {
  11. return [
  12. 'id' => $data->id,
  13. 'name' => $data->getTranslation('name'),
  14. 'banner' => uploaded_asset($data->banner),
  15. 'icon' => uploaded_asset($data->icon),
  16. 'number_of_children' => CategoryUtility::get_immediate_children_count($data->id),
  17. 'links' => [
  18. 'products' => route('api.products.category', $data->id),
  19. 'sub_categories' => route('subCategories.index', $data->id)
  20. ]
  21. ];
  22. })
  23. ];
  24. }
  25. public function with($request)
  26. {
  27. return [
  28. 'success' => true,
  29. 'status' => 200
  30. ];
  31. }
  32. }