How to Implement Infinite Scroll in Laravel
Wern Ancheta has a good tip about building infinite scroll in Laravel.
In this quick tip I’ll be showing you how to easily implement infinite scroll in laravel. In the back-end, we will be using laravel’s pagination functionality. And in the front-end, we’ll be using jQuery infinite scroll. You can ahead and download the jquery.infinitescroll.min.js file from that page and save it on your project directory.
First thing that you need to do is return the data that you want to infinitely scroll from the controller:
<?php public function getNewsPage(){ $date = date('Y-m-d'); $news = News::where('date', '=', $date)->paginate(10); $page_data = array( 'news' => $news ); return View::make('news', $page_data); } ?>
And then from your view file (news.blade.php) just loop through the items that you wish to output:
<div id="news"> <ul id="items"> @foreach($news as $item) <li class="item"> <a href="" target="_blank"></a> </li> @endforeach </ul> </div>
Be sure to include jquery and jquery.infinitescroll.min.js file before the closing body tag:
<script src=""></script> <script src=""></script> </body>
Next, create the javascript file that will call the infinitescroll plugin and add th
Link:
This post is submitted by our members. Submit a new post.
Topics: PHP Jquery Laravel Javascript
Tags: Tutorials Laravel 5 Laravel 5.1 Laravel 5.2 v4.x v4.1 v4.2 Intermediate Tips