user3019749
user3019749

Reputation: 81

Laravel order by desc

I'm trying to get this order by descend working, but for some reason an error keeps being thrown which is:

BadMethodCallException in View.php line 387: Method [orderBy] does not exist on view.

I'm not sure why it can't find the orderBy method.

public function display()
{
    return view('users/timeline')
        ->with('user_name', 'body', 'location',
            'photo', 'visibility', 'created_at')
        ->with('posts', Posts::all());
        ->orderBy('created_at', 'desc')
        ->get();
}

Upvotes: 2

Views: 5893

Answers (2)

AnasSafi
AnasSafi

Reputation: 6264

Now you can use orderByDesc directly:

Posts::orderByDesc('created_at')->get();

Upvotes: 2

Alexey Mezenin
Alexey Mezenin

Reputation: 163838

It should be:

Posts::orderBy('created_at', 'desc')->get();

Upvotes: 3

Related Questions