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

后端 未结 4 657
深忆病人
深忆病人 2020-11-30 21:54

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

 SELECT * FROM  `games` LIMIT 30 , 30 

And with Eloquent ?

4条回答
  •  佛祖请我去吃肉
    2020-11-30 22:14

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

提交回复
热议问题