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">
@if(isset($users))
<h2>Sample User details</h2>
    <table class="table table-striped">
        <thead>
            <tr>
                <th>Name</th>
                <th>Email</th>
            </tr>
        </thead>
        <tbody>
            @foreach($users as $dummy)
            <tr>
                <td>{{$dummy->name}}</td>
                <td>{{$dummy->email}}</td>
            </tr>
            @endforeach

        </tbody>
    </table>
    {!! $users->render() !!}@endif
</div>

Complete Post Link

http://justlaravel.com/paginated-data-search-laravel/?utm_source=learninglaravel.net

Working Demo

http://justlaravel.com/demos/pagination-and-search/?utm_source=learninglaravel.net

Github Link

https://github.com/avinashn/Pagination-and-Search-Laravel/?utm_source=learninglaravel.net