Download the PHP package thybag/bonus-laravel-relations without Composer
On this page you can find all versions of the php package thybag/bonus-laravel-relations. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download thybag/bonus-laravel-relations
More information about thybag/bonus-laravel-relations
Files in thybag/bonus-laravel-relations
Package bonus-laravel-relations
Short Description Additional eloquent ORM relation types for laravel.
License MIT
Informations about the package bonus-laravel-relations
Bonus Eloquent relations for Laravel
A selection of weird & wonderful additional relation types for laravel's eloquent ORM I've ended up needing.
Many of these are experimental and may behave in unexpected & none standard ways.
On the bright side - it's tested!
All licensed under the MIT license.
Usage.
- Install via composer using
composer require thybag/bonus-laravel-relations
- Include the
use thybag\BonusLaravelRelations\Traits\BonusRelationsTrait;
in to your model (or base model if you want them everywhere.) - Use the relations as you would any other.
The relation traits can also be added individually if you prefer that.
- Run tests with
composer test
- Run lint with
composer lint
Relations
BelongsToMorph
Get polymorphic relations of a single type.
HasManyViaMany
Define a relation via an unlimited number of middle tables.
HasAggregate
Get an aggregate result as a relation. The main benefit of this approach is it allows easy lazy loading of this data on collections + interaction with the results in a more eloquent like way.
HasMethod
Use a local method as if it were a relation.
BelongsToOne
Define a one-to-one relation through a pivot table.
InertModel
As the relationships HasMethod
and HasAggregate
don't return a traditional model from the database, a special model called type InertModel
is used. This allows the relationship to fill the model with arbitrary attributes without the risk of causing unexpected behavior.
If you would like to use a custom InertModel rather than the one provided, create a config called bonus-laravel-relationships.php
in your config folder, then set the value inertModel
with the class path to the model you would like to use instead. I would recommend whatever model you use inherits from the base IntertModel to avoid unexpected behavior.