Nikki
373
2
Laravel

Method Illuminate\Database\Eloquent\Collection::orderBy does not exist.

Posted 4 months ago by Nikki

I've made a list and now I'm trying to use orderBy to sort the orders by order_date. The problem I'm getting is this error

Method Illuminate\Database\Eloquent\Collection::orderBy does not exist.

I can't see where I went wrong.

Here is my code

public function trackOrders()
    {
        $menus_child = Menu::where('menu_id', 0)->with('menusP')->get();
        $contacts = Contact::all();

        $orders = Auth::user()->orders;
        $order->transform(function($order, $key){
            $order->cart = unserialize($order->cart);
            return $order;
        })->orderBy('order_date', 'desc');

        return view('public.users.track-orders', compact('menus_child', 'contacts', 'orders', 'order_item'));
    }

I've also tried

$order_test = $orders->orderBy('order_date', 'desc')->get();

and I still got the same error

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