Sometimes in our project we must need to add group by with the multiple columns. Today now in this p ost i will show you How to use multiple columns group by in Laravel Query Builder? if we are mysql query then easily we can do this by using sql query. But when we want to give with multiple columns in groupBy() in our Laravel Query Builder then we need to give by using comma separated.
$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);
Read Also : Laravel 8 Mobile Number Verification Tutorial
Thanks for read. I hope it help you. For more you can follow us on facebook