PHPackages                             soyhuce/laravel-eloquent-extended - 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. soyhuce/laravel-eloquent-extended

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

soyhuce/laravel-eloquent-extended
=================================

Some useful extensions for Eloquent

1.9.0(2mo ago)111.4k[3 PRs](https://github.com/Soyhuce/laravel-eloquent-extended/pulls)MITPHPPHP ^8.3CI passing

Since Apr 8Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/Soyhuce/laravel-eloquent-extended)[ Packagist](https://packagist.org/packages/soyhuce/laravel-eloquent-extended)[ Docs](https://github.com/soyhuce/laravel-eloquent-extended)[ GitHub Sponsors](https://github.com/soyhuce)[ RSS](/packages/soyhuce-laravel-eloquent-extended/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (13)Versions (16)Used By (0)

Some useful extensions for Eloquent
===================================

[](#some-useful-extensions-for-eloquent)

[![Latest Version on Packagist](https://camo.githubusercontent.com/0452663a3afab60d405b728e01807ca78dd362104fe0ea09ea010cf6c41df857/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736f79687563652f6c61726176656c2d656c6f7175656e742d657874656e6465642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/soyhuce/laravel-eloquent-extended)[![GitHub Tests Action Status](https://camo.githubusercontent.com/93ad2ee0691b42f2838a06615c02ea1300e16d5c97d54e3d165f6c45c47d87b1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f736f79687563652f6c61726176656c2d656c6f7175656e742d657874656e6465642f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/soyhuce/laravel-eloquent-extended/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/add3c0b0c1c230c734827a03e48b8d78b43d10cc10a471d8f9230d6404f498d4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f736f79687563652f6c61726176656c2d656c6f7175656e742d657874656e6465642f7068702d63732d66697865722e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/soyhuce/laravel-eloquent-extended/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![GitHub PHPStan Action Status](https://camo.githubusercontent.com/c70010bf09297e81210e9eacddfc49681568829dd2e5e791caf492bf13402035/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f736f79687563652f6c61726176656c2d656c6f7175656e742d657874656e6465642f7068707374616e2e796d6c3f6272616e63683d6d61696e266c6162656c3d7068707374616e)](https://github.com/soyhuce/laravel-eloquent-extended/actions?query=workflow%3APHPStan+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/2c9018d054a83661aebb964a4277e94977dc3dc24425421eff9b66b3b7eefba9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736f79687563652f6c61726176656c2d656c6f7175656e742d657874656e6465642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/soyhuce/laravel-eloquent-extended)

This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require soyhuce/laravel-eloquent-extended
```

Usage
-----

[](#usage)

Builder
-------

[](#builder)

### Misc

[](#misc)

- Builder::scope(Illuminate\\Database\\Eloquent\\Scope $score): Builder
- Builder::scoped(\\Closure $callable): Builder

### Ordering

[](#ordering)

- Builder::preventInvalidDirection(string $direction): void
- Builder::orderByNullsLast(string $column, string $direction = 'asc'): Builder
- Builder::orderByRawNullsLast(string $sql): Builder
- Builder::orderByAggregate( string $relationName, string $column, string $direction = 'asc', ?string $function = null, ?Closure $constraints = null)
- Builder::orderByExists(string $relation, ?Closure $constraints = null, string $direction = 'asc')
- Builder::orderByExistsDesc(string $relation, ?Closure $constraints = null)
- Builder::orderByCount(string $relation, ?Closure $constraints = null, string $direction = 'asc')
- Builder::orderByCountDesc(string $relation, ?Closure $constraints = null)
- Builder::orderBySum(string $relation, string $column, ?Closure $constraints = null, string $direction = 'asc')
- Builder::orderBySumDesc(string $relation, string $column, ?Closure $constraints = null)
- Builder::orderByMin(string $relation, string $column, ?Closure $constraints = null, string $direction = 'asc')
- Builder::orderByMinDesc(string $relation, string $column, ?Closure $constraints = null)
- Builder::orderByMax(string $relation, string $column, ?Closure $constraints = null, string $direction = 'asc')
- Builder::orderByMaxDesc(string $relation, string $column, ?Closure $constraints = null)

### Result

[](#result)

- Builder::random(): Model

### Select

[](#select)

- Builder::withAggregateFunction( $relations, \\Soyhuce\\EloquentExtended\\Aggregates\\Contracts\\AggregateFunction $aggregateFunction): Builder
- Builder::withAnyExists(array $relations, string $alias = 'related\_exists') : Builder
- Builder::withImplode($relations, string $column, string $glue, ?string $orderBy = null, string $direction = 'asc') : Builder

### Creation

[](#creation)

- Builder::insertModels(array $values): bool
- Builder::upsertModels(array $values, string|array $uniqueBy, ?array $update = null): int
- Builder::insertModelsReturning(array $values, array $returning = \['\*'\]): Collection (requires tpetry/laravel-postgresql-enhanced)
- Builder::upsertModelsReturning(array $values, string|array $uniqueBy, ?array $update = null, array $returning = \['\*'\]): Collection (requires tpetry/laravel-postgresql-enhanced)

Eloquent Collection
-------------------

[](#eloquent-collection)

- Collection::loadAttributes(Closure(Builder): Builder|void $loadWith): Collection

Model traits
------------

[](#model-traits)

### LoadsAttributes

[](#loadsattributes)

- Model::loadAttributes(Closure(Builder): Builder|void $loadWith): Model

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Bastien Philippe](https://github.com/bastien-phi)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

53

—

FairBetter than 97% of packages

Maintenance87

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 50.6% 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 ~142 days

Total

11

Last Release

74d ago

PHP version history (3 changes)1.0.0PHP ^8.1

1.4.0PHP ^8.2

1.7.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/206cfbf866a463f7e7d1e86946d59b82f4191b9c89f9981fb03eeb264d77af79?d=identicon)[SoyHuCe](/maintainers/SoyHuCe)

---

Top Contributors

[![bastien-phi](https://avatars.githubusercontent.com/u/10199039?v=4)](https://github.com/bastien-phi "bastien-phi (41 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (19 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (13 commits)")[![ElRochito](https://avatars.githubusercontent.com/u/1737307?v=4)](https://github.com/ElRochito "ElRochito (4 commits)")[![EdenMl](https://avatars.githubusercontent.com/u/70885551?v=4)](https://github.com/EdenMl "EdenMl (3 commits)")[![tnajah59](https://avatars.githubusercontent.com/u/91531929?v=4)](https://github.com/tnajah59 "tnajah59 (1 commits)")

---

Tags

eloquenthacktoberfestlaravellaraveleloquentsoyhuce

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/soyhuce-laravel-eloquent-extended/health.svg)

```
[![Health](https://phpackages.com/badges/soyhuce-laravel-eloquent-extended/health.svg)](https://phpackages.com/packages/soyhuce-laravel-eloquent-extended)
```

###  Alternatives

[silber/bouncer

Eloquent roles and abilities.

3.6k4.4M25](/packages/silber-bouncer)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[io238/laravel-iso-countries

Ready-to-use Laravel models and relations for country (ISO 3166), language (ISO 639-1), and currency (ISO 4217) information with multi-language support.

5462.3k](/packages/io238-laravel-iso-countries)

PHPackages © 2026

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