Is there a way to "limit" the result with ELOQUENT ORM of Laravel?

Natan Shalva picture Natan Shalva · Mar 5, 2013 · Viewed 169.4k times · Source

Is there a way to "limit" the result with ELOQUENT ORM of Laravel?

 SELECT * FROM  `games` LIMIT 30 , 30 

And with Eloquent ?

Answer

Muhammad Usman picture Muhammad Usman · Mar 5, 2013

Create a Game model which extends Eloquent and use this:

Game::take(30)->skip(30)->get();

take() here will get 30 records and skip() here will offset to 30 records.


In recent Laravel versions you can also use:

Game::limit(30)->offset(30)->get();