有没有办法“限制” Laravel的ELOQUENT ORM的结果? [英] Is there a way to "limit" the result with ELOQUENT ORM of Laravel?

查看:175
本文介绍了有没有办法“限制” Laravel的ELOQUENT ORM的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法用Laravel的ELOQUENT ORM限制结果?

  SELECT * FROM`games` LIMIT 30,30 

与雄辩?

解决方案

创建一个扩展口才的游戏模型,并使用:

 游戏::采取(30) - >跳过(30) - >得到(); 

take()这里将获得30条记录和 skip()这里将会抵消30条记录。






在最近的Laravel版本中,您还可以使用:

  Game :: limit(30) - > offset(30) - >得到(); 


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

 SELECT * FROM  `games` LIMIT 30 , 30 

And with Eloquent ?

解决方案

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

这篇关于有没有办法“限制” Laravel的ELOQUENT ORM的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆