Can I use the with function with a GroupBy clause in Laravel Rloquent? Is it used for any purpose if I have certain items to select with the Select clause?
Below is the query that I have
Order::with('Campaign') ->where('isapproved','=','Y') ->groupBy('campaign_id') ->orderBy(DB::raw('COUNT(id)','desc')) ->get(array(DB::raw('COUNT(id) as totalsales')));
The order table has the column name campaign_id , in which belongsTo table called campaigns . I would like to get the total number of sales from the table of orders against each campaign and show them as follows.
Total Sales Campaign ------------------------- 200 Campaign1 500 Campaign2 300 Campaign3
Do I have to make a specific selection or can I access the values of the Campaign table from the above query?
source share