Good day!
There was a situation in the code.
There is a table
news,
news_tags,
tagsI have displayed news using
elasticsearch and there is a global event and listen to the updates of this model is to rebuild the updated data in elasticsearch in any action in this model.
\\Event::listen( ['eloquent.updated*', 'eloquent.created*', 'eloquent.deleted*'], function ($event, $params) { list($model) = $params; if ($model instanceof ModelSearch) { /** @var ElasticSearchService $service */ $service = app()->make(ElasticSearchService::class); if (strpos($event, 'eloquent.updated') === 0) { $service->update($model); } if (strpos($event, 'eloquent.created') === 0) { $service->add($model); } if (strpos($event, 'eloquent.deleted') === 0) { $service->delete($model); } } } );
But when I tied the tags to this model, they are stored in the staging table and the news model does not react.
How do I get it updated?
I see several solutions:
- Update updated_at from news thereby cause event
- Raise the event manually \\Event::fire('eloquent.updated: '. get_class($news), [$news]);
Maybe there are better choices in this situation?