How to use multiple columns groupby in Laravel Query Builder

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

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.

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);

Read Also : Laravel 8 Mobile Number Verification Tutorial

Thanks for read. I hope it help you. For more you can follow us on facebook

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →