I have a code:
$orders = Order::all();
$allorders = $orders->count();
$deliveryQuery = $orders->where('status', '=', '8')->select(DB::raw('AVG(updated_at) as order_average'))->first();
I get error:
Method select does not exist.
How I can fix it? My code is working, if I do:
$deliveryQuery = Order::where('status', '=', '8')->select(DB::raw('AVG(updated_at) as order_average'))->first();
But this not good, I want 1 query, but not 2..
UPDATE:
$orders->where('status', '=', '8')->avg('updated_at')->first();
I can use this code? But it not working..Get error:
Object of class Illuminate\Support\Carbon could not be converted to int