Ad

Paginate Large Data In Laravel

- 1 answer

Good day, I just want to ask on how to handle a large amount of data to be display in my table. For instance, I have a table in my app and it will be fetching millions of data and paginate it by 100. What is the best approach in doing this?

Ad

Answer

You just need to paginate it, instead of fetching whole table to memory (that will be heavy).

In raw SQL it is done by LIMIT X OFFSET Y

In Laravel eloquent's pagination() is doing this for You, for ex. User::paginate(100);

Then You simply foreach this data in Your table, and put pagination links under it.

Read more https://laravel.com/docs/7.x/pagination

Ad
source: stackoverflow.com
Ad