Avinash wrote a tutorial on how to add pagination with search functionality to our Laravel application.

paginated laravel

Paginated data with Search functionality – Laravel

Its quite common to inculude search option and pagination functionality for displaying any type of large data. So instead of using some table table extenders which fetch all the records at a time its better to use built in paginators which only gets the required number of records each time.

Here in this elegant framework, Laravel, its quite easy to implement these functionalities with very few lines of code.

We ‘ll show a chunks of dummy data with about 1000 rows and limiting to only 25 rows per page. This dummy data is collected from Mockaroo.com

The route file,

  Route::get ( '/', function () {
    $dummyDetails = User::paginate(25);
    return view ( 'welcome' )->withUsers($dummyDetails);
} );

Now in the view file, welcome.blade.php, we show this data limiting to only 25 results per page.

<div class="container">
<h2>Sample User details</h2>
    <table class="table table-striped">
            @foreach($users as $dummy)

    {!! $users->render() !!}@endif

Complete Post Link


Working Demo


Github Link