Laravel Load More Data on Page Scroll – Laravel 5

In this post exercise, we will disclose to you how to Laravel Load More Data from database utilizing jQuery and PHP Laravel.

Laravel Load More Data:: we are all comfortable and familiar with load more method in Facebook, Youtube and so on. Today we will demonstrate to you generally accepted methods to progressively stack the information on a catch click as opposed to showing the pagination joins. Stack more procedure makes your site more intelligent in light of the fact that the information is stacked without invigorating the page. In this post exercise, we utilize innovations like Ajax, Jquery, Bootstrap and so forth to make a lovely load more information method in the most straightforward way.

we don’t have need to click anyplace to load information since information is stacking on page scroll consequently from MySQl database.

There are such a variety of site that utilization a similar rationale to load information on page look over, this is extremely helpful with a few cases.

It will check if information length is equivalent to 0 then show message for “No more records!” and if information length is more than 0 then it add html information to list.

Here is a straightforward stride to tell you about stacking information naturally on page look through and through utilizing jQuery and PHP.

SO LET’S START CODING for Laravel Load More Data on Page Scroll

1) Create Table and Model for Laravel Load More Data on Page Scroll

namespace App;

use Illuminate\Database\Eloquent\Model;
// Create Post Model
class Post extends Model

2) Add Routes for Laravel Load More Data on Page Scroll

 // add Route for Laravel Load More Data
 // routes/web.php Laravel 5.3 or 5.4
 // app/Http/web.php Laravel 5 to 5.2

 Route::post('demos/loaddata','LoadController@DataAjaxload' );

3) Create LoadController for Laravel Load More Data on Page Scroll

The Helper is a custom helper file created by me to load image thumbnail of each post. If you like to learn more about how to create custom helper function in laravel visit following link.

4) Create View Page for Laravel Load More Data on Page Scroll

The javascript code for in the view page

Since we are using post ajax request in laravel we need to in like manner pass csrf tokens nearby the code since laravel reliably scan for csrf tokens in the post and put requests. In case we don’t pass it we will get a 500 goof. The inspiration driving why i used $(document).on('click',id,function(){}); instead of essential catch click limit is whether we use get click work the catch snap will trigger only the principal gone through. The reason that the handler is simply being ended once is because of the “.snap” handler just applies to parts that are at this moment affixed to the DOM. If you supplant the HTML ensuing to making the AJAX call, the event handlers will be lost. So you should use an on strategy.

The Complete View Page for Laravel Load More Data