How to group by multiple columns in Laravel Query Builder?

How to group by multiple columns in Laravel Query Builder?

In this post we will give you information about How to group by multiple columns in Laravel Query Builder?. Hear we will give you detail about How to group by multiple columns in Laravel Query Builder?And how to use it also give you demo for it if it is necessary.

Sometimes we may require to add group by with multiple columns, if we have mysql query then we can do it easily by using sql query. But if you want to give multiple columns in groupBy() of Laravel Query Builder then you can give by comma separated values as bellow example.

Example:

$data = DB::table("items_count")

->select(

'items_count.*'

,DB::raw("SUM(items_count.quantity) as total_quantity"))

->groupBy('items_count.id_item','items_count.id_cat')

->get();

print_r($data);

Hope this code and post will helped you for implement How to group by multiple columns in Laravel Query Builder?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

30  +    =  37

We accept paid advance and paid guest Posting on our Site : Contact US