https://github.com/parallax/observe-relationships
Automatically trigger indexing based on relational data changes
https://github.com/parallax/observe-relationships
Last synced: 12 months ago
JSON representation
Automatically trigger indexing based on relational data changes
- Host: GitHub
- URL: https://github.com/parallax/observe-relationships
- Owner: parallax
- Created: 2020-05-05T14:16:29.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-05T15:15:10.000Z (about 6 years ago)
- Last Synced: 2025-06-30T00:11:22.502Z (12 months ago)
- Language: PHP
- Size: 4.88 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Observe Relationships
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
```bash
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:
```bash
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:
```php
return [
'models' => [
\App\Models\Page::class => [
[
'model' => \App\Models\Product::class,
'field' => 'page_id'
]
]
]
];
```