Warm tip: This article is reproduced from stackoverflow.com, please click
laravel

Is it possible to use a where clause in a Laravel collection that has been called via a get() functi

发布于 2020-03-27 15:45:13

As the above question; Is there any way possible to use a where clause on a Collection?

These are my codes;

$order = \App\Order::where('user_id', $input['user_id'])
->whereBetween('created_at', array($date_from_formatted, $date_to_formatted))
->get();

Note that when i dd($order) my collection returns just fine

$online_order = $order->where('ord_type', 'Onl')
                ->where('paid', 'Y')
                 ->whereIn('status', $param);
$online_order->all();

Note that when i dd($online_order) i get an empty collection

Am i doing something wrong with my $online_order?

Questioner
Udhayan Nair
Viewed
17
Kamlesh Paul 2020-01-31 17:01

make $order to model instance so you can use where() with it

$order = \App\Order::where('user_id', $input['user_id'])
        ->whereBetween('created_at', array($date_from_formatted, $date_to_formatted));
orderValue = $order->get();

and other

$online_order = $order->where('ord_type', 'Onl')
                ->where('paid', 'Y')
                 ->whereIn('status', $param);
$online_order->all();