Laravel挑选清单的简单电子商务逻辑

时间:2018-09-20 07:12:11

标签: laravel eloquent e-commerce laravel-blade laravel-query-builder

我正在努力创建一个简单的逻辑。.我有订单的集合…某些订单中有相同的产品..但数量不同..我想创建这些订单的拣配清单.. 例如。

  • Order1 = iphone xs:1
  • Order2 = iphone xs:2,iphone xs max:1
  • Order3 = iphone xs:1,iphone xr:2
  • Order4 = iphone xs max:2

我当前的代码:

@php
$x = $allorders->pluck('SKU')->all();
@endphp
@foreach ($x as $z)
    @foreach ($allorders->where('SKU', $z)->pluck('quantity_ordered') as $grouporder)
        {{$z}} : {{$grouporder}} <br>
    @endforeach
@endforeach

输出如下:

  • iphone xs:1
  • iphone xs:2
  • iphone xs:1
  • iphone xs max:1
  • iphone xs max:2
  • iphone xr:2

相反,我该如何显示它: 因此我的选择列表将显示:

  • iphone xs:4
  • iphone xs max:3
  • iphone xr:2

1 个答案:

答案 0 :(得分:0)

select SKU, sum(quantity_ordered), min(title) from product_details group by SKU

这对我有用..谢谢:)