artificertech / laravel-relationship-events

Missing relationship events for Laravel
MIT License
12 stars 1 forks source link

Support for BelongsToMany relationships #1

Open f-liva opened 3 years ago

f-liva commented 3 years ago

Do you plan to support BelongsToMany relationship events as well?

coleshirley commented 3 years ago

Long story short I am not going to add any new events for the ManyToMany relationships because Laravel already allows us to create custom pivot models which have their own set of model events that fire when the relationship is altered. https://laravel.com/docs/8.x/eloquent-relationships#defining-custom-intermediate-table-models

I am planning on adding documentation to this package that explains my reasoning above.

The only thing that is not very convenient when using the pivot model events as they are now is only the id's of the two associated models are available in the pivot model events. This makes it so if you need to find additional information about the two associated models you have to reload them from the database which is an inefficient extra query assuming you already loaded the models in order to attach them in the first place.

I am planning on looking into a way to make it so those extra database queries are not needed but I have not found a solution yet