Answer the question
In order to leave comments, you need to log in
How to correctly trigger an event?
Good afternoon!
There was a situation in the code.
There is a table news , news_tags , tags
I have news displayed through elasticsearch and there is a global event for listening to the update of this model in order to rebuild the updated data in elasticsearch for any actions 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);
}
}
}
);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question