How can I group by relation?
Example
Sales::with('product_detail.product')->groupBy('product_name')->get()
How can I get a result with eloquent code?
You can specify a callback function for grouping your relation like this:
Sales::with(['product_detail.product' => function($query){
$query->groupBy('product_name');
}])->get();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With