Jul 5, 2015
0
Level 1
Manual pagination after sorting won't render
I have this code
$lessons = Lesson::approved()->get();
$lessons = $lessons->sortBy(function($lesson){
return $lesson->getViewCount();
});
$lessons = $lessons->reverse();
$lessons = new Paginator($lessons, 3);
$lessons->setPath('sort');
$lessons->appends(['sort' => 'viewdesc']);
is there something wrong with my code? I couldn't use simplePaginate because I need to sort my collection using my custom function (getViewCount), so this is what I tried. However, when I click on next page button, the page url parameter changes to page 2, 3 etc, but it always show the same collection :/ (page 1)
I tried this too, btw
$lessons = Lesson::approved()->get();
$lessons = $lessons->sortBy(function($lesson){
return $lesson->getViewCount();
});
$lessons = $lessons->reverse();
$lessons = new Paginator($lessons->slice((3*$page)-3, 6), 3);
$lessons->setPath('sort');
$lessons->appends(['sort' => 'viewdesc']);
and this time, the next and previous button won't even render. funny thing is, if I manually change the page parameter on URL, the content will change accordingly.
Please or to participate in this conversation.