PHPackages                             palmosolutions/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. palmosolutions/eloquent-eager-limit

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

palmosolutions/eloquent-eager-limit
===================================

Laravel Eloquent eager loading with limit

12.0(10mo ago)0491MITPHPPHP ^8.3

Since Jan 24Pushed 10mo agoCompare

[ Source](https://github.com/Palmosolutions/eloquent-eager-limit)[ Packagist](https://packagist.org/packages/palmosolutions/eloquent-eager-limit)[ Fund](https://paypal.me/JonasStaudenmeir)[ RSS](/packages/palmosolutions-eloquent-eager-limit/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (3)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

36

—

LowBetter than 81% of packages

Maintenance58

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~167 days

Total

2

Last Release

303d ago

Major Versions

11.0 → 12.02025-07-10

### Community

Maintainers

![](https://www.gravatar.com/avatar/4ce609b00747d9e521a6b8a130c44ad186447d2c0883dc3a0d4b527d61cf3357?d=identicon)[vladkovrigin](/maintainers/vladkovrigin)

---

Top Contributors

[![staudenmeir](https://avatars.githubusercontent.com/u/1853169?v=4)](https://github.com/staudenmeir "staudenmeir (93 commits)")[![vladkovrigin](https://avatars.githubusercontent.com/u/74209000?v=4)](https://github.com/vladkovrigin "vladkovrigin (3 commits)")[![mpyw](https://avatars.githubusercontent.com/u/1351893?v=4)](https://github.com/mpyw "mpyw (2 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)")[![gdebrauwer](https://avatars.githubusercontent.com/u/22586858?v=4)](https://github.com/gdebrauwer "gdebrauwer (1 commits)")[![crishoj](https://avatars.githubusercontent.com/u/20393?v=4)](https://github.com/crishoj "crishoj (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[owen-it/laravel-auditing

Audit changes of your Eloquent models in Laravel

3.4k33.0M95](/packages/owen-it-laravel-auditing)[staudenmeir/eloquent-json-relations

Laravel Eloquent relationships with JSON keys

1.1k5.8M24](/packages/staudenmeir-eloquent-json-relations)[bavix/laravel-wallet

It's easy to work with a virtual wallet.

1.3k1.1M11](/packages/bavix-laravel-wallet)[dragon-code/migrate-db

Easy data transfer from one database to another

15717.4k](/packages/dragon-code-migrate-db)[gearbox-solutions/eloquent-filemaker

A package for getting FileMaker records as Eloquent models in Laravel

6454.8k2](/packages/gearbox-solutions-eloquent-filemaker)[cybercog/laravel-ownership

Laravel Ownership simplify management of Eloquent model's owner.

9126.6k3](/packages/cybercog-laravel-ownership)

PHPackages © 2026

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