mardi 12 mars 2019

Order list not ordering by order_date

I created a page that lists all the items in a database that matches the logged in user, the problem I'm having is that my list doesn't want to be ordered by the order date.

This is my code

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

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

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

I've also tried removing this

->sortByDesc('order_date');

and adding this

->orderBy('order_date', 'desc');

but then I got this error

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



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire