I am trying to use paginate()
to achieve infinite scroll. I think the easiest way is to use the "endless scroll" to achieve this. If you have any other suggestion on how to do this without an infinite scroll library, just using jQuery, I would be happy to know.
I return the variable to view as follows:
public function index()
{
$posts = Post::with('status' == 'verified')
->paginate(30);
return view ('show')->with(compact('posts'));
}
My view:
<div id="content" class="col-md-10">
@foreach (array_chunk($posts->all(), 3) as $row)
<div class="post row">
@foreach($row as $post)
<div class="item col-md-4">
</div>
@endforeach
</div>
@endforeach
{!! $posts->render() !!}
</div>
Javascript part:
$(document).ready(function() {
(function() {
var loading_options = {
finishedMsg: "<div class='end-msg'>End of content!</div>",
msgText: "<div class='center'>Loading news items...</div>",
img: "/assets/img/ajax-loader.gif"
};
$('#content').infinitescroll({
loading: loading_options,
navSelector: "ul.pagination",
nextSelector: "ul.pagination li:last a",
itemSelector: "#content div.item"
});
});
});
However, this does not work. The part → render () works because I get the [<[1] 2] 3]>] part. However, the endless scroll does not work. I also do not get any errors in the console.
[<[1] 2] 3]>] is as follows: source:
<ul class="pagination">
<li class="disabled"><span>«</span> </li> // «
<li class="active"><span>1</span></li> // 1
<li><a href="http://test.dev/?page=2">2</a></li> // 2
<li><a href="http://test.dev/?page=3">3</a></li> // 3
<li><a href="http://test.dev/?page=2" rel="next">»</a></li> // »
</ul>