PosProductCollection.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace App\Http\Resources;
  3. use App\Models\ProductTranslation;
  4. use Illuminate\Http\Resources\Json\ResourceCollection;
  5. class PosProductCollection extends ResourceCollection
  6. {
  7. public function toArray($request)
  8. {
  9. return [
  10. 'data' => $this->collection->map(function ($data) {
  11. $lang = session('locale');
  12. $name = $data->name;
  13. if ($lang != 'en') {
  14. $name = ProductTranslation::query()->where('product_id', $data->id)->where('lang', $lang)->pluck('name');
  15. $name = isset($name[0]) ? $name[0] : $data->name;
  16. }
  17. return [
  18. 'id' => $data->id,
  19. 'stock_id' => $data->stock_id,
  20. 'name' => $name,
  21. 'thumbnail_image' => ($data->stock_image == null) ? uploaded_asset($data->thumbnail_img) : uploaded_asset($data->stock_image),
  22. 'price' => home_discounted_base_price_by_stock_id($data->stock_id),
  23. 'base_price' => home_base_price_by_stock_id($data->stock_id),
  24. 'qty' => $data->stock_qty,
  25. 'variant' => $data->variant,
  26. ];
  27. })
  28. ];
  29. }
  30. public function with($request)
  31. {
  32. return [
  33. 'success' => true,
  34. 'status' => 200
  35. ];
  36. }
  37. }