Is there a way to "limit" the result with ELOQUENT ORM of Laravel?
是否有一种方法可以“限制”拉拉乌尔雄辩的结果?
SELECT * FROM `games` LIMIT 30 , 30
And with Eloquent ?
和有说服力的?
3 个解决方案
#1
191
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.
这里将有30条记录和skip()将被记录到30条记录。
In recent Laravel versions you can also use:
在最近的Laravel版本中,你也可以使用:
Game::limit(30)->offset(30)->get();
#2
12
If you're looking to paginate results, use the integrated paginator, it works great!
如果您希望分页结果,请使用集成的分页符,它非常有用!
$games = Game::paginate(30);
// $games->results = the 30 you asked for
// $games->links() = the links to next, previous, etc pages
#3
3
We can use LIMIT like bellow:
我们可以使用如下限制:
Model::take(20)->get();
#1
191
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.
这里将有30条记录和skip()将被记录到30条记录。
In recent Laravel versions you can also use:
在最近的Laravel版本中,你也可以使用:
Game::limit(30)->offset(30)->get();
#2
12
If you're looking to paginate results, use the integrated paginator, it works great!
如果您希望分页结果,请使用集成的分页符,它非常有用!
$games = Game::paginate(30);
// $games->results = the 30 you asked for
// $games->links() = the links to next, previous, etc pages
#3
3
We can use LIMIT like bellow:
我们可以使用如下限制:
Model::take(20)->get();