问题
Is there a way to \"limit\" the result with ELOQUENT ORM of Laravel?
SELECT * FROM `games` LIMIT 30 , 30
And with Eloquent ?
回答1:
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();
回答2:
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:
We can use LIMIT like bellow:
Model::take(20)->get();
来源:https://stackoverflow.com/questions/15229303/is-there-a-way-to-limit-the-result-with-eloquent-orm-of-laravel