Paginated data with Search functionality – laravel

Paginated data with Search functionality – laravel

In previous posts we saw about pagination and search functionality individually. Here we ‘ll combine search functionality with paginated data results.

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.

First 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.

Working Demo      Project on Github

for reference, you can find the dummy details sql file here

Pagination View :

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

Search functionality with paginated data - justLaravel.com
Search functionality with paginated data – justLaravel.com

Search Form :

Now we ‘ll use the form for search field which we created in previous post on Search functionality.

Pagination and Search logic :

The logic for a handling search is,

Working Demo      Project on Github

Here we used HTTP method any() Route::any() but in previous post on search we used HTTP method post() Route::post(). The difference is in previous post we just fetch data from the database and show the result, as we are interacting with database we should use post method, where as here we first fetch the all the data(all 1000 records) so post method and then we show only 5 results(paginated value here is 5)of them, so when we click next button of the pagination then we should get the already obtained results, so here get method is used. As we are using both post and get methods . We write the route as Route::any()

Search functionality with paginated data - justLaravel.com
Search functionality with paginated data – justLaravel.com

Here while showing search results we limited data to only 5 results per page.

 

Working Demo      Project on Github

That’s it folks we ‘ve successfully implemented search functionality with paginatated data. Make sure you ‘ve gone through previous posts on search and pagination.



5 thoughts on “Paginated data with Search functionality – laravel”

  • 18
    123 on April 5, 2017 Reply

    thanks)

    • 19
      avinash on April 6, 2017 Reply

      For more such tutorials follow justlaravel.com

  • 20
    jemirisselvi on August 4, 2017 Reply

    good

Leave a Reply