MySQL 有没有办法用 Laravel 的 ELOQUENT ORM 来“限制”结果?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15229303/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a way to "limit" the result with ELOQUENT ORM of Laravel?
提问by Natan Shalva
Is there a way to "limit" the result with ELOQUENT ORM of Laravel?
有没有办法用 Laravel 的 ELOQUENT ORM 来“限制”结果?
SELECT * FROM `games` LIMIT 30 , 30
And with Eloquent ?
和雄辩?
回答by Muhammad Usman
Create a Game model which extends Eloquent and use this:
创建一个扩展 Eloquent 的游戏模型并使用它:
Game::take(30)->skip(30)->get();
take()
here will get 30 records and skip()
here will offset to 30 records.
take()
此处将获得 30 条记录,skip()
此处将偏移为 30 条记录。
In recent Laravel versions you can also use:
在最近的 Laravel 版本中,您还可以使用:
Game::limit(30)->offset(30)->get();
回答by fregante
回答by srmilon
We can use LIMIT like bellow:
我们可以像下面这样使用 LIMIT:
Model::take(20)->get();