【发布时间】:2018-07-06 14:27:55
【问题描述】:
我的数据库如下:
id |group_id |property_id |type |
1 | 9 | 13 |property |
2 | 9 | 14 |property |
3 | 9 | 15 |property |
4 | 9 | 14 |variant |
5 | 8 | 14 |property |
6 | 8 | 15 |variant |
7 | 8 | 13 |property |
我的代码如下:
$stock_get_property = StockPropertyTemplate::groupBy('group_id')->selectRaw('count(type) as quantity , group_id')->where('type' , 'property')->get();
$stock_get_variant = StockPropertyTemplate::groupBy('group_id')->selectRaw('count(type) as quantity , group_id')->where('type' , 'variant')->get();
我想要对它们进行总分组。 groupBy('group_id') 按 type="property" 和 "variant"。如何合并两个查询?
我要创建的数组输出如下;
id |group_id |count_property|count_variant|
1 | 9 | 3 | 1 |
2 | 8 | 2 | 1 |
我怎样才能用 Laravel 做到这一点?请帮帮我:(
【问题讨论】:
标签: php arrays laravel laravel-5