Reputation:
I have List. List has many posts.
I want to get all post of some lists, sort posts and paginate it.
I try this:
$list = List::whereId('1')->firstOrFail();
$posts = $feed->posts()->orderBy('id')->paginate(Request::input('per_page'))->appends(Request::input());
return compact('list','posts');
Now I can get List and paginate posts, but ordeBy doesn't work? How order it? Or any other way to solve this problem?
Upvotes: 3
Views: 62
Reputation: 366
->orderBy('id','asc') for Ascending
->orderBy('id','desc') for Decending
Upvotes: 0
Reputation: 163768
It works and sorts by ASC
by default. If you want to reverse it, use DESC
:
->orderBy('id', 'desc')
Or:
->latest('id')
Upvotes: 0