Download the PHP package stayallive/laravel-inverse-relations without Composer

On this page you can find all versions of the php package stayallive/laravel-inverse-relations. 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-inverse-relations

Laravel Inverse Relations

Latest Version Build Status Total Downloads

HasMany, HasOne and MorphMany Eloquent relations with inverse hydration.

Jonathan Reinink wrote a great blog post about optimizing circular relationships in Laravel. The package stancl/laravel-hasmanywithinverse ran with that idea and implemented it for the hasMany relation. This package improves on that by implementing it for the hasOne and morphMany relations too.

In short, this package allows you to define inverse relations on your models. This means that you can define a relation on a model that points to another model. This is useful when you have a circular relationship between two models and you want to be able to access the inverse relation without having to load the other model from the database potentially saving a lot of database queries.

Installation

Usage

Adding the HasHasManyWithInverseRelation, HasHasOneWithInverseRelation and/or HasMorphManyWithInverseRelation traits will provide you with the helper methods to setup the inverse relations.

Check out the test stubs for examples on how to implement the traits on your models to setup the inverse relations:

Caveats

Because the inverse relation stores the parent by reference (not cloned), you need to be careful when you are using the relation since you will be modifying the parent model. This is nothing new to this package since eager loading does the same thing but I thought to mention it since it could catch you off guard.

There is one other downside to the inverse relation being stored as a reference since it creates a circular reference. This means that you cannot recusively serialize the model that has the inverse relation. Laravel does this for example when you pass the model in a queued job since the SerializesModels trait will also try to store which relations were loaded when the model was queued to load those relations back causing once the job is being processed. This causes an infinite loop trying to figure out which relations are loaded recursively, eating up memory until the process is killed by the OS or crashes.

To prevent this you can either pass your model to your job using $model->withoutRelations() or you can disable the relations loading on your model by adding the following method to your model:

This disables the collection and loading of relations on the model when it (un-)serialized for the queued job.

Personally I put this in my base model since I never want to load the relations loaded when I push a job on the queue since they are mostly not useful in the context of the job and apart from guarding against circular references this also saves database queries (sometimes a lot) retrieving unused relations.

Security Vulnerabilities

If you discover a security vulnerability within this package, please send an e-mail to Alex Bouma at [email protected]. All security vulnerabilities will be swiftly addressed.

License

This package is open-sourced software licensed under the MIT license.


All versions of laravel-inverse-relations with dependencies

PHP Build Version
Package Version
Requires laravel/framework Version ^8|^9|^10|^11
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 stayallive/laravel-inverse-relations contains the following files

Loading the files please wait ....