0

I am taking sum of all orders by week, month and year. My code is like this:

$current_day = Order::whereDate('created_at', Carbon::today())
                    ->where('order_status', 'Complete')
                    ->sum('total_amount');
$current_week = Order::whereBetween('created_at', [Carbon::now()->startOfWeek(), Carbon::now()->endOfWeek()])
                    ->where('order_status', 'Complete')
                    ->sum('total_amount');
$current_month = Order::whereMonth('created_at', date('m'))
                    ->whereYear('created_at', date('Y'))
                    ->where('order_status', 'Complete')
                    ->sum('total_amount');

How can I take all this information by one SQL request?

3

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.