staudenmeir/eloquent-eager-limit
Larablocks Analysis
Compatibility
Trusted maintainerstaudenmeir/eloquent-eager-limit works with Laravel 10 (latest release v1.8.3, Jul 12, 2023), which reached end of life on Feb 4, 2025: no more fixes, even for security.
Laravel 5 to 9 in earlier releases.
- Trusted maintainer: staudenmeir publishes 15 packages on Larablocks, with 5,204,163 downloads a month between them.
Recommendation checks
Not advisedNot advised: no release or commit in over 2 years.
- No release or commit in over 2 years
- Supports only Laravel 10, past end of life since Feb 4, 2025
- No release in the last 12 months (last: Jul 12, 2023)
- 38,612 downloads a month (at least 10,000)
- 884 GitHub stars (at least 100)
State
Likely abandoned- No release or commit in over 2 years.
- Last stable release: Jul 12, 2023.
- No releases in the last 12 months.
- First released: Oct 24, 2018.
- Monthly downloads: 38,612, down 26% from six months ago.
- 0 open issues on GitHub.
Data from Packagist and GitHub, checked by Larablocks on Dec 1, 2026.
| Install | |
|---|---|
composer require staudenmeir/eloquent-eager-limit |
|
| Latest Version: | v1.8.3 |
| PHP: | ^8.1 |
| Laravel: | 10 |
| Older releases: | 5 – 9 |
| License: | MIT |
| Last Updated: | Jul 14, 2024 |
| Links: | GitHub · Packagist |
Eloquent Eager Limit
[!IMPORTANT] The package's code has been merged into Laravel 11+ and eager loading limits are now supported natively.
This Laravel Eloquent extension allows limiting the number of eager loading results per parent using window functions.
Supports Laravel 5.5–10.
Compatibility
- MySQL 5.7+
- MySQL 5.5~5.6: Due to a bug in MySQL, the package only works with strict mode disabled.
In yourconfig/database.phpfile, set'strict' => false,for the MySQL connection. - MariaDB 10.2+
- PostgreSQL 9.3+
- SQLite 3.25+: The limit is ignored on older versions of SQLite. This way, your application tests still work.
- SQL Server 2008+
Installation
composer require staudenmeir/eloquent-eager-limit:"^1.0"
Use this command if you are in PowerShell on Windows (e.g. in VS Code):
composer require staudenmeir/eloquent-eager-limit:"^^^^1.0"
Versions
| Laravel | Package |
|---|---|
| 10.x | 1.8 |
| 9.x | 1.7 |
| 8.x | 1.6 |
| 7.x | 1.5 |
| 6.x | 1.4 |
| 5.8 | 1.3 |
| 5.5–5.7 | 1.2 |
Usage
Use the HasEagerLimit trait in both the parent and the related model and apply limit()/take() to your relationship:
class User extends Model
{
use \Staudenmeir\EloquentEagerLimit\HasEagerLimit;
public function posts()
{
return $this->hasMany('App\Post');
}
}
class Post extends Model
{
use \Staudenmeir\EloquentEagerLimit\HasEagerLimit;
}
$users = User::with(['posts' => function ($query) {
$query->latest()->limit(10);
}])->get();
Improve the performance of HasOne/HasOneThrough/MorphOne relationships by applying limit(1):
class User extends Model
{
use \Staudenmeir\EloquentEagerLimit\HasEagerLimit;
public function latestPost()
{
return $this->hasOne('App\Post')->latest()->limit(1);
}
}
class Post extends Model
{
use \Staudenmeir\EloquentEagerLimit\HasEagerLimit;
}
$users = User::with('latestPost')->get();
You can also apply offset()/skip() to your relationship:
class User extends Model
{
use \Staudenmeir\EloquentEagerLimit\HasEagerLimit;
public function posts()
{
return $this->hasMany('App\Post');
}
}
class Post extends Model
{
use \Staudenmeir\EloquentEagerLimit\HasEagerLimit;
}
$users = User::with(['posts' => function ($query) {
$query->latest()->offset(5)->limit(10);
}])->get();
Package Conflicts
staudenmeir/laravel-adjacency-list: Replace both packages with staudenmeir/eloquent-eager-limit-x-laravel-adjacency-list to use them on the same model.staudenmeir/laravel-cte: Replace both packages with staudenmeir/eloquent-eager-limit-x-laravel-cte to use them on the same model.topclaudy/compoships: Replace both packages with mpyw/compoships-eager-limit to use them on the same model.
Contributing
Please see CONTRIBUTING and CODE OF CONDUCT for details.
Related Packages
Powerful PHP database abstraction layer (DBAL) with many features for database s...
Laravel Serializable Closure provides an easy and secure way to serialize closur...
Cli error handling for console/command-line PHP applications.
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| v1.8.3 | ^8.1 | ^10.0 | MIT | |
| v1.8.2 | ^8.1 | ^10.0 | MIT | |
| v1.8.1 | ^8.1 | ^10.0 | MIT | |
| v1.8 | ^8.1 | ^10.0 | MIT | |
| v1.7.1 | ^8.0.2 | ^9.0 | MIT | |
| v1.7 | ^8.0.2 | ^9.0 | MIT | |
| v1.6.1 | ^7.3| | ^8.0 | MIT | |
| v1.6 | ^7.3 | ^8.0 | MIT | |
| v1.5.1 | ^7.2.5| | ^7.0 | MIT | |
| v1.5 | ^7.2.5 | ^7.0 | MIT | |
| v1.4.1 | ^7.2.5| | ^6.0 | MIT | |
| v1.4 | ^7.2 | ^6.0 | MIT | |
| v1.3.1 | ^7.1.3 | 5.8.* | MIT | |
| v1.3 | ^7.1.3 | 5.8.* | MIT | |
| v1.2.1 | >=7.0 | ^5.5.14 | MIT | |
| v1.2 | >=7.0 | ^5.5.14 | MIT | |
| v1.1 | >=7.0 | ^5.5.14 | MIT | |
| v1.0.2 | >=7.0 | ^5.5.14 | MIT | |
| v1.0.1 | >=7.0 | ^5.5.14 | MIT | |
| v1.0 | >=7.0 | ^5.5.14 | MIT |
