How to get daily record and sum up
How to get the daily record and sum them up, plus group it by date? Please see my code below.
$sales = DB::table("orders")
->where('status', 8)
->select(
'grand_total',
'order_date',
DB::raw("SUM(grand_total) as total_sales")
)
->groupBy('order_date')
->get();
dd($sales);
It returns the right dates, but wrong sales. How can I sum sales each day?
Do you mean the sales that have been made per date to represent total_sales? Or the amount that has been (in terms of money I guess) made in total?
If it's the first, I guess you can do a COUNT(id) instead of SUM(grand_total). You would have to have an id column on your orders table of course.
Please or to participate in this conversation.