有没有办法用Laravel的ELOQUENT ORM来“限制”结果?
SELECT * FROM `games` LIMIT 30 , 30
和雄辩?
有没有办法用Laravel的ELOQUENT ORM来“限制”结果?
SELECT * FROM `games` LIMIT 30 , 30
和雄辩?
Answers:
如果您想分页显示结果,请使用集成的分页器,效果很好!
$games = Game::paginate(30);
// $games->results = the 30 you asked for
// $games->links() = the links to next, previous, etc pages
另外,我们可以通过以下方式使用它
只得到第一
$cat_details = DB::table('an_category')->where('slug', 'people')->first();
通过限制和抵消
$top_articles = DB::table('an_pages')->where('status',1)->limit(30)->offset(0)->orderBy('id', 'DESC')->get();
$remaining_articles = DB::table('an_pages')->where('status',1)->limit(30)->offset(30)->orderBy('id', 'DESC')->get();