I have a laravel event with multiple listeners. Some listeners or their notifications (depending on how much time they take) implement ShouldQueue, so they run in the background in a queue redis. The event uses SerializesModelsby default, but when one of the transmitted models for the event is a registered user, and we fire it, for example:
$user = $this->user();
event(new UserCreatedPost($user, $post, $modelX, $modelY));
I cannot access user subscribers in the appropriate listener to check if they should be notified if they exist:
public function handle(UserCreatedPost $event){
$followers = $event->user->followers()->get();
}
I get this error:
Call to undefined method Illuminate\Contracts\Database\ModelIdentifier::followers()
The only way I was able to get it to work was to add an event trigger below:
public function handle(UserCreatedPost $event){
$event->__wakeup();
$followers = $event->user->followers()->first();
}
I do $user . , $user , , SerializesModels ( , ).
$user wakeup? , , wakeup , , . SerializesModels , , . - , , , , , , ? ?