New

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

soyhuce/laravel-eloquent-extended

Some useful extensions for Eloquent
12,918 1
Install
composer require soyhuce/laravel-eloquent-extended
Latest Version:1.9.0
PHP:^8.3
Laravel:11 · 12
Older releases:9 · 10
License:MIT
Last Updated:Apr 20, 2026
Links: GitHub  ·  Packagist
Maintainer: SoyHuCe

Some useful extensions for Eloquent

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status GitHub PHPStan Action Status Total Downloads

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

Installation

You can install the package via composer:

composer require soyhuce/laravel-eloquent-extended

Usage

Builder

Misc

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

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

  • Builder::random(): Model

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

  • 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

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

Model traits

LoadsAttributes

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

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

Related Packages

sofa/hookable

Laravel Eloquent hooks system.

2,049,184 65
volosyuk/simple-eloquent

Adaptation of eloquent for retrieving its attributes

117,433 55
gzero/eloquent-tree

Eloquent Tree is a tree model for Laravel Eloquent ORM.

59,480 131
martinbean/laravel-sluggable-trait

A trait you can apply to Eloquent models to have slugs automatically generated o...

49,105 24
isswp101/elasticsearch-eloquent

Elasticsearch functionality like Laravel Eloquent models.

25,356 112

Version History

Version Released PHP Laravel License
1.9.0 ^8.3 ^11.0|^12.0 MIT
1.8.0 ^8.3 ^11.0|^12.0 MIT
1.7.1 ^8.3 ^11.0 MIT
1.7.0 ^8.3 ^11.0 MIT
1.6.0 ^8.2 ^10.0 || ^11.0 MIT