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


Answers:



17

如果您想分页显示结果,请使用集成的分页器,效果很好!

$games = Game::paginate(30);
// $games->results = the 30 you asked for
// $games->links() = the links to next, previous, etc pages

3
这真是太神奇了!使用引导程序,您实际上需要的所有代码都是$ games = Game :: paginate(30)在您的控制器中,而{{$ games-> links()}}在您的视图中……它可以处理所有事情。爱Laravel!
david_nash


0

另外,我们可以通过以下方式使用它

只得到第一

 $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();
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.