Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ruskidragonball's avatar

Deleted user notification problem

Hello all,

I have a UserObserver class and I want to send an email notification to the user when he will be deleted from the database. So in the deleted() method I have

Notification::route('mail', $user->email)->notify(new UserDeleted($user));

Notification is queable but it doesn't work. Because propably when it is executed no model exists. How is it possible to manage this situation?

0 likes
4 replies
mstrauss's avatar

To avoid any complex, probably unnecessary logic, like temporarily storing the deleted user's email address, you may just have to send the notification immediately in this case.

Or, if you're only using their email address (and not any of the other User model properties) in the UserDeleted notification class, just send the email variable to the Queue, as it will not need to reference the User at that point.

siangboon's avatar

i would probably have columns to indicate the status and duration of the users about to be deleted and have a schedule to check daily and send notification to the user before deleting it.

Snapey's avatar

pass the user as an array rather than user object?

new UserDeleted($user->toArray());

and amend your UserDeleted class to accept array of user attributes

or soft delete the user and change the notification to access deleted model

Please or to participate in this conversation.