My database as below:
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 |
My code as below:
$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();
I want the total grouping them. groupBy('group_id') by type="property" and "variant". How can I combine two queries?
the array output I want to create as below;
id |group_id |count_property|count_variant|
1 | 9 | 3 | 1 |
2 | 8 | 2 | 1 |
How can I do it with Laravel? Please help me :(