samedi 27 janvier 2018

How to by same id with group by i find to multiple column ? - Laravel

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:

$info = StockPropertyTemplate::select(DB::raw('count(*) as type'))->where("type" , "variant")->where("type" , "property")
            ->groupBy('group_id')
            ->get();

I want the total grouping them. groupBy('group_id') by type="property" and "variant".

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?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2GiJipT
via IFTTT

Aucun commentaire:

Enregistrer un commentaire