Jonjie
2 months ago
247
1
Laravel

How to get daily record and sum up

Posted 2 months ago by Jonjie

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?

Please sign in or create an account to participate in this conversation.