pagination

Laravel simplePaginate: more effective with bigger data

Laravel pagination is quite a simple thing to use, but to determine the amount of pages it makes additional query to the database, which may be a problem for bigger amount of data. And you can actually avoid it.

Let’s take a simple pagination example from a table with 5000 customers:

And then in Blade file you have this:

Here’s how the queries look in Laravel Debugbar.

Laravel pagination

As you can see, there’s query for the actual page, and then counting the amount of entries/pages.

What if you don’t need the numbers of pages and you just want to show links for Previous and Next? There’s a function for that called simplePaginate().

Laravel simplepaginate

Now, look at the amount of queries.

Hope that helps!

Want to generate Laravel adminpanel online?
You don't need any packages to do that!

3 thoughts on “Laravel simplePaginate: more effective with bigger data

  1. Looking at both picture i am lil confushed. The solutions you have provided for bigger data is slower and consuming more memory according to the screenshots you have posted.

      1. Yes the info is actually correct. But the screenshot were not reflecting it. And it ‘s not complex or simple query IMHO as the query will not slow down the application because of large data. It is just going it minimize a loop to render pagination number. And if you look at the query time there is only 2ms difference.

        Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *