An open API service indexing awesome lists of open source software.

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

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'
]
]
]
];
```