A Projector that listens to all ShouldBeStored Events #293
Answered
by
brendt
fabianpnke
asked this question in
Q&A
-
I've extended the default ShouldBeStored Event to include the current user_id as a property/meta field. Currently doing this: class UserActivityProjector extends Projector implements ShouldQueue
{
private function updateUserActivity(ShouldBeStored $event)
{
if ($event->auth_id === null) {
return;
}
User::find($event->auth_id)
?->writeable()
?->updateQuietly([
'last_active_at' => $event->createdAt(),
]);
}
public function onUserCreated(UserCreated $event)
{
$this->updateUserActivity($event);
}
} Would like to do something like this: class UserActivityProjector extends Projector implements ShouldQueue
{
public function onShouldBeStored(ShouldBeStored $event)
{
if ($event->auth_id === null) {
return;
}
User::find($event->auth_id)
?->writeable()
?->updateQuietly([
'last_active_at' => $event->createdAt(),
]);
} Thanks for your help and some ideas, |
Beta Was this translation helpful? Give feedback.
Answered by
brendt
Nov 26, 2021
Replies: 1 comment
-
v6 allows you to listen to union types and even class UserActivityProjector extends Projector implements ShouldQueue
{
public function onAllEvents(ShouldBeStored $event)
{
}
} class UserActivityProjector extends Projector implements ShouldQueue
{
public function onAllEvents(object $event)
{
}
} class UserActivityProjector extends Projector implements ShouldQueue
{
public function onAllEvents(ActivityEvent|LoggableEvent $event)
{
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
fabianpnke
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
v6 allows you to listen to union types and even
object
:) a few variations: