I am using laravel and I need to find the eloquent query for: get all the records in a date range, group them by day and sum all the values.
sales table is:
-id
-total_cost
-total_sale
-profit
I have tried this way, it returns the query grouped by day but I can't find the way to add the totals.
$sales = Venta::whereMonth('created_at', Carbon::now()->month)
->where('user_id', Auth::user()->id)
->whereYear('created_at', '=', '2022')
->get()
->groupBy(function($date) {
return Carbon::parse($date->created_at)->format('d');
});
Any suggestions?