PHPackages                             two-faces/eloquent-eager-limit - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. two-faces/eloquent-eager-limit

ActiveLibrary[Database &amp; ORM](/categories/database)

two-faces/eloquent-eager-limit
==============================

Laravel Eloquent eager loading with limit

045PHP

Since Dec 15Pushed 4mo agoCompare

[ Source](https://github.com/Two-Faces/eloquent-eager-limit)[ Packagist](https://packagist.org/packages/two-faces/eloquent-eager-limit)[ RSS](/packages/two-faces-eloquent-eager-limit/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Eloquent Eager Limit
====================

[](#eloquent-eager-limit)

[![CI](https://github.com/staudenmeir/eloquent-eager-limit/actions/workflows/ci.yml/badge.svg)](https://github.com/staudenmeir/eloquent-eager-limit/actions/workflows/ci.yml)[![Code Coverage](https://camo.githubusercontent.com/9d901e0e680a7a829b283e040d42c3296c60154f7853ad74bf3b34b1a7482967/68747470733a2f2f636f6465636f762e696f2f67682f7374617564656e6d6569722f656c6f7175656e742d65616765722d6c696d69742f67726170682f62616467652e7376673f746f6b656e3d4a387973626431723830)](https://codecov.io/gh/staudenmeir/eloquent-eager-limit)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/7cba9496b1c603e867e3cadf5267496fabae1dcecfa1a18ec2053d1172d46ed4/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7374617564656e6d6569722f656c6f7175656e742d65616765722d6c696d69742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/staudenmeir/eloquent-eager-limit/?branch=main)[![Latest Stable Version](https://camo.githubusercontent.com/b8edc6fb62c2db2548a3175c0f01cb5a23d0385d5b771a45fe6c2ed38a1c9f39/68747470733a2f2f706f7365722e707567782e6f72672f7374617564656e6d6569722f656c6f7175656e742d65616765722d6c696d69742f762f737461626c65)](https://packagist.org/packages/staudenmeir/eloquent-eager-limit)[![Total Downloads](https://camo.githubusercontent.com/4ae245abf7792e5ea234a3b50455831037380a39362f61308af33332ea1ebe84/68747470733a2f2f706f7365722e707567782e6f72672f7374617564656e6d6569722f656c6f7175656e742d65616765722d6c696d69742f646f776e6c6f616473)](https://packagist.org/packages/staudenmeir/eloquent-eager-limit/stats)[![License](https://camo.githubusercontent.com/12467cba2c0433f3327a4d4a385756eaeec9fff4543f7d843c649e86f0d63bc4/68747470733a2f2f706f7365722e707567782e6f72672f7374617564656e6d6569722f656c6f7175656e742d65616765722d6c696d69742f6c6963656e7365)](https://github.com/staudenmeir/eloquent-eager-limit/blob/main/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](https://en.wikipedia.org/wiki/Select_(SQL)#Limiting_result_rows).

Supports Laravel 5.5–10.

Compatibility
-------------

[](#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
------------

[](#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
--------

[](#versions)

LaravelPackage10.x1.89.x1.78.x1.67.x1.56.x1.45.81.35.5–5.71.2Usage
-----

[](#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

[](#package-conflicts)

- `staudenmeir/laravel-adjacency-list`: Replace both packages with [staudenmeir/eloquent-eager-limit-x-laravel-adjacency-list](https://github.com/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](https://github.com/staudenmeir/eloquent-eager-limit-x-laravel-cte)to use them on the same model.
- `topclaudy/compoships`: Replace both packages with [mpyw/compoships-eager-limit](https://github.com/mpyw/compoships-eager-limit)to use them on the same model.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) and [CODE OF CONDUCT](.github/CODE_OF_CONDUCT.md) for details.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance50

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 Bus Factor1

Top contributor holds 91.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/8d82c785b4d58a08843201d12550893fa500d91cb521d1e0fc891cf49f54e169?d=identicon)[ariesel](/maintainers/ariesel)

---

Top Contributors

[![staudenmeir](https://avatars.githubusercontent.com/u/1853169?v=4)](https://github.com/staudenmeir "staudenmeir (93 commits)")[![Two-Faces](https://avatars.githubusercontent.com/u/32146703?v=4)](https://github.com/Two-Faces "Two-Faces (2 commits)")[![mpyw](https://avatars.githubusercontent.com/u/1351893?v=4)](https://github.com/mpyw "mpyw (2 commits)")[![jocoonopa](https://avatars.githubusercontent.com/u/4261007?v=4)](https://github.com/jocoonopa "jocoonopa (1 commits)")[![bonzai](https://avatars.githubusercontent.com/u/98191?v=4)](https://github.com/bonzai "bonzai (1 commits)")[![NiekVelde](https://avatars.githubusercontent.com/u/14216593?v=4)](https://github.com/NiekVelde "NiekVelde (1 commits)")[![crishoj](https://avatars.githubusercontent.com/u/20393?v=4)](https://github.com/crishoj "crishoj (1 commits)")[![gdebrauwer](https://avatars.githubusercontent.com/u/22586858?v=4)](https://github.com/gdebrauwer "gdebrauwer (1 commits)")

### Embed Badge

![Health badge](/badges/two-faces-eloquent-eager-limit/health.svg)

```
[![Health](https://phpackages.com/badges/two-faces-eloquent-eager-limit/health.svg)](https://phpackages.com/packages/two-faces-eloquent-eager-limit)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.3k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M543](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M209](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
