SearchProductCollection.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Http\Resources\V2;
  3. use Illuminate\Http\Resources\Json\ResourceCollection;
  4. class SearchProductCollection 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. 'thumbnail_image' => uploaded_asset($data->thumbnail_img),
  13. 'base_price' => (double) home_base_price($data, false),
  14. 'base_discounted_price' => (double) home_discounted_base_price($data, false),
  15. 'rating' => (double) $data->rating,
  16. 'links' => [
  17. 'details' => route('products.show', $data->id),
  18. 'reviews' => route('api.reviews.index', $data->id),
  19. 'related' => route('products.related', $data->id),
  20. 'top_from_seller' => route('products.topFromSeller', $data->id)
  21. ]
  22. ];
  23. })
  24. ];
  25. }
  26. public function with($request)
  27. {
  28. return [
  29. 'success' => true,
  30. 'status' => 200
  31. ];
  32. }
  33. }