Answer the question
In order to leave comments, you need to log in
Why doesn't paginate() work with sortBy method on laravel?
I'm trying to make pagination on laravel, but here's what happened.
If you display a list of news in 5 pieces, then I do this
and everything works fine. I display links to pages through {!! $news->render() !!}
But I need the records to be retrieved from the database sorted by a certain field.
Without pagination, I did it like this.
But if I add the paginate () method, i.e.
then it swears that the paginate () method was not found.
I tried to do this
in this case, the selection occurred, the records were displayed, but links to pages are not displayed, i.e. does not work {!! $news->render() !!} (writes that the render() method was not found).
I broke my whole head, I don’t understand how to display posts with pagination while applying sorting. $news = News::paginate(5);
$news = News::all()->sortBy('sort');
$news = News::all()->sortBy('sort')->paginate(5)
News::all()->paginate(5)->sortBy('sort')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question