How to raise an event?

0 like 0 dislike
7 views
Good day!

There was a situation in the code.
There is a table news, news_tags, tags
I 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:
  1. Update updated_at from news thereby cause event
  2. Raise the event manually \\Event::fire('eloquent.updated: '. get_class($news), [$news]);


Maybe there are better choices in this situation?
by | 7 views

1 Answer

0 like 0 dislike
There's such a thing
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked May 20, 2019 by VitaliyBorys
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
33,921 users