parallax / observe-relationships
observe Relationships
Requires
- laravel/framework: ^5.5 | 6.* | 7.*
This package is auto-updated.
Last update: 2024-11-06 01:33:07 UTC
README
This package allows you to configure specific models to trigger update observers for other possible related models.
Whilst Laravel does support the touches
method, you might be using a package model instance where you cannot define the parent -> child relationship,
therefore cannot enable $touches
method. This package does the same thing but controlled via configuration.
E.g. A product might relate to a page, but if the page is change the model doesn't re-index currently. This package allows that to work via config and observes.
Installation
composer require parallax/observe-relationships
Configuration
On installation the configuration file should be published to your /config
folder. If it is not then run the following:
php artisan vendor:publish --provider=Parallax\ObserveRelationship\ObserveRelationshipProvider
Inside thie /config/observe-relationship.php
you will see an empty array of models.
The key is the model you want to watch, then the sub arrays are the models you want to trigger.
The required fields for a trigger is model
and field
. On a save of the watcher instance it will
update the updated_at
timestamps of the trigger model.
Example
An example configuration of a Page
model being watched for a change event that will trigger a Product
model to be seen as updated is:
return [ 'models' => [ \App\Models\Page::class => [ [ 'model' => \App\Models\Product::class, 'field' => 'page_id' ] ] ] ];