Download the PHP package caue-santos/laravel-model-utils without Composer

On this page you can find all versions of the php package caue-santos/laravel-model-utils. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-model-utils

Laravel Model Utils

GitHub Workflow Status Packagist Packagist Packagist

Eloquent helpers for the query-building problems that don't have a clean built-in solution: joining a relation chain by hand with stable, collision-free aliases; nested aggregate scopes (count/sum/avg/min/max) across a dot-notation relation path several hops deep; registering runtime relation aliases (including automatically-generated reverse relations for a forward chain, so it can be traversed leaf-to-root); and reflecting a model's own relation methods (type, keys, pivot, belongsToThrough chain) without maintaining that metadata by hand.

Requirements

Installation

The service provider is auto-discovered.

Core concepts

Concept What it is
ModelHelpers Static helpers for manual relation joins (loadRelationWithJoin, whereHasRelationWithJoin) and runtime relation registration (with, registerAliasedRelation, registerAliasedRelationWithFilters).
Traits\RelationshipsTrait Add to a model to reflect its own relations (relationships()), check a dot-path exists (hasDefinedRelation()), and auto-register reverse relations for a forward chain (defineReverseRuntimeRelations()).
Traits\HasWithAggregatesRelation Add to a model for scopeWithNestedCount/Sum/Avg/Max/Min/CountUnique — aggregate scopes across a dot-notation relation path.
Traits\HasRecursiveRelation Adds scopeWhereRelationDepth(), a thin wrapper over ModelHelpers::whereHasRelationWithJoin().
Traits\HasRelationInspector Adds a static hasRelation() check — does this dot-path resolve to a real relation, including relations registered via resolveRelationUsing()?

Joining a relation chain manually

ModelHelpers::loadRelationWithJoin() walks a dot-separated relation path (HasOne, HasMany, BelongsTo, BelongsToMany) and joins every hop with a generated, collision-free alias — reusing an existing join if the same query already walked that path:

ModelHelpers::whereHasRelationWithJoin() builds on the same join machinery to add a WHERE EXISTS constraint instead of eager-loading columns:

ModelHelpers::getJoinedAliases() / aliasFor() let other code (e.g. a sort/filter layer built on top of this package) look up which alias a given relation path already joined to, instead of re-deriving it.

Nested aggregate scopes

A non-nested relation (no . in the path) delegates straight to Laravel's own withAggregate(); a nested one builds the correlated subquery + joins itself, walking HasOne/HasMany/BelongsTo/BelongsToMany hops with generated aliases (t1, t2, ...) and applying the constraint callback against the final hop's alias — passed explicitly as the callback's second argument so a constraint targeting the base relation's own columns and one targeting the deepest joined table are never ambiguous. withNestedCount/Sum/Avg/Max/Min also accept an array to add several aggregates in one call:

Reflecting a model's relations

Every public, zero-argument model method whose return type is (or includes, for a union return type) an Illuminate\Database\Eloquent\Relations\Relation subclass is reflected automatically — BelongsTo, HasOne, HasMany, BelongsToMany, and staudenmeir/belongs-to-through's BelongsToThrough are all recognised, each with the key pair/pivot/through-chain metadata relevant to that relation type. Runtime relations registered via Model::resolveRelationUsing() are included too.

hasDefinedRelation('company.industry') walks a dot-path through that same reflection and returns the resolved chain (or false if any hop doesn't exist) — defineReverseRuntimeRelations() uses it to register the inverse of each hop on the corresponding child model (namespaced per parent, so different chains sharing a child model don't collide), returning the reversed dot-path a caller can hand to whereHas() to query the chain leaf-to-root.

Testing

Changelog

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

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits


All versions of laravel-model-utils with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/database Version ^6.0|^7.0|^8.0|^9.0|^10.0|11.*
illuminate/support Version ^6.0|^7.0|^8.0|^9.0|^10.0|11.*
staudenmeir/belongs-to-through Version ^2.13
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package caue-santos/laravel-model-utils contains the following files

Loading the files please wait ...