Is there a way to "limit" the result with ELOQUENT ORM of Laravel?
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
When using the Laravel Framework's Eloquent Object Relational Mapper (ORM) for database interactions, it provides various methods to retrieve data efficiently. Sometimes, you may need to limit the results returned by a query. In this post, we will explore different techniques to do so and provide some best practices while working with Eloquent ORM.
Pagination
One of the most common ways to limit result sets is through pagination. Laravel comes with built-in support for pagination, which you can use on your database interactions as well. The `paginate()` method returns a Paginator instance containing the model instances. You can specify the number of results per page by passing it as an argument:php
$games = Game::paginate(20); // Display 20 games per pageOffset Limit Syntax
In certain cases, you may need to manually limit the results. You can use Laravel's query builder's offset and limit methods along with Eloquent models:php
$games = Game::orderBy('created_at', 'desc')->offset(30)->limit(15)->get(); // Retrieve 15 games starting from the 31st gameEager Loading & Relationships
Another method to limit results is by optimizing your database queries through eager loading and relationships. Eloquent provides a way to load associated models simultaneously, thereby reducing the number of queries required:php
$usersWithGames = User::with('games')->get(); // Load users with their games in one queryCustom Scopes
If you require a more permanent solution for limiting results or need a specific logic, you can define custom scopes on your Eloquent model. A scope allows you to set up query conditions before retrieving data:php
public function scopeLatestGames($query) {
return $query->where('created_at', '>', now()->subDay());
}php
$recentGames = Game::latestGames()->get(); // Retrieve only the latest games