New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

staudenmeir/eloquent-eager-limit

Laravel Eloquent eager loading with limit
4,001,994 884

Larablocks Analysis

Compatibility

Trusted maintainer

staudenmeir/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 advised

Not 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
Maintainer: staudenmeir

Eloquent Eager Limit

CI Code Coverage Scrutinizer Code Quality Latest Stable Version Total Downloads License

[!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 your config/database.php file, 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

Contributing

Please see CONTRIBUTING and CODE OF CONDUCT for details.

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

670,032,257 9,703
laravel/framework

The Laravel Framework.

640,572,096 35,338
laravel/tinker

Powerful REPL for the Laravel framework.

546,909,908 7,440
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

465,816,364 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

438,010,529 4,660

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