Search code examples
mysqllaraveleloquentsql-limit

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


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

 SELECT * FROM  `games` LIMIT 30 , 30 

And with Eloquent ?


Solution

  • 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();