I have a question about laravel pagination and infinite scroll :
First of all, I have this :
-
I've found the solution (for you, people of the future) :
$('#boxes').infinitescroll({
navSelector : ".paginate",
nextSelector : ".paginate a:last",
itemSelector : ".box",
debug : false,
dataType : 'html',
path: function(index) {
return "?page=" + index;
}
}, function(newElements, data, url){
var $newElems = $( newElements );
$('#boxes').masonry( 'appended', $newElems, true);
});
This works because :
- The pagination given by laravel 4 is like we saw before
- The pagination in laravel give an url like ....?page=x
IMPORTANT
The bug you will encounter is :
When you scroll down beyond what should be the last page, you’ll probably find that you keep getting the last page over and and over again, causing genuinely infinite scrolling.
to fix this, go to the paginator.php (in the laravel folder) and change it as follow :
if (is_numeric($page) and $page > $last = ceil($total / $per_page))
{
return Response::error('404');
}
Hope it will help someone someday !