uccdev

Paginate a database's complete results?

Posted 1 month ago by uccdev

Hi, I need help with paginating my database.

Basically, I want to do a complete query from my DB, and I want to chunk it off so that only certain sections of it are given at a time - the rest can be scrolled through via pagination.

e.g:

   $dairies = DB::table('dairies')
select('name', 'stock')
->get();

This would return every entry in the 'dairies' table, all 20,000+ of them.

I know of the "->paginate(num)" extension I can add to my DB::table, like so instead of 'get':

   ->paginate(50);

But what I need to do isn't simply to paginate the result. I need to spread it out so that, rather than load all 100,000+ entries in the DB, I only load, say, 50 at a time, and hitting the 'next' or 'previous' button will get the next batch of 50 after that.

Does anyone know how to do this? If you could spare the time, your help would be greatly appreciated!

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.