Make notifications for successful Reset password Email sent.

I wanna the email especially in reset password can provide the correct notifications, because the notifications when click sending email only show succesful sent email even though, it still being queue, I want it to give notifications according the job executing. I have event to listen to this event when job being success or fail like this.
class PasswordResetQueueListener
{
/**
* Handle job success.
* Especially for sending emails
*/
public function handleSuccess(JobProcessed $event)
{
if ($this -> isRequestPasswordReset($event)) {
// Notify user in Filament
Notification::make()
->title('Email telah dikirim, tolong cek inbox Anda')
->success()
->broadcast($this -> retrieveIdUser($event));
return false;
}
}

/**
* Handle job failure.
* Especially for sending emails
*/
public function handleFailure(JobFailed $event)
{
if($this -> isRequestPasswordReset($event)){
$notification = Notification::make()
->title('Gagal mengirim email.')
->body('Error: ' .$event->exception->getMessage())
->danger()
->broadcast($this->retrieveIdUser($event));
return false;
}
}

public function isRequestPasswordReset($event){
return $event->job->resolveName() === 'Filament\Notifications\Auth\ResetPassword';
}

public function retrieveIdUser($event){
$payload = $event->job->payload();
$user = unserialize($payload['data']['command'])->notifiables;
return $user;
}
}
class PasswordResetQueueListener
{
/**
* Handle job success.
* Especially for sending emails
*/
public function handleSuccess(JobProcessed $event)
{
if ($this -> isRequestPasswordReset($event)) {
// Notify user in Filament
Notification::make()
->title('Email telah dikirim, tolong cek inbox Anda')
->success()
->broadcast($this -> retrieveIdUser($event));
return false;
}
}

/**
* Handle job failure.
* Especially for sending emails
*/
public function handleFailure(JobFailed $event)
{
if($this -> isRequestPasswordReset($event)){
$notification = Notification::make()
->title('Gagal mengirim email.')
->body('Error: ' .$event->exception->getMessage())
->danger()
->broadcast($this->retrieveIdUser($event));
return false;
}
}

public function isRequestPasswordReset($event){
return $event->job->resolveName() === 'Filament\Notifications\Auth\ResetPassword';
}

public function retrieveIdUser($event){
$payload = $event->job->payload();
$user = unserialize($payload['data']['command'])->notifiables;
return $user;
}
}
But there's one problem which the broadcast will not work because the user is not have connection to channel when not log in. So I think to make temporary channel for it which make random uuid or smth like that and it need to pass in the job to being retrieve. Please help me, because this my first time work with php and laravel
3 Replies
Mohamed Ayaou
Mohamed Ayaou3w ago
Sorry for not understanding your issue very will but I think you can just user the DatabaseNotifications instead of the normal notifications? Why would you send a Toast notification for unavailable user from the first place?
kiuyha
kiuyhaOP3w ago
like I said before it for the forget password, so the user not yet login if I use DatabaseNotifications then the user will not get notifications that the email have sent

Did you find this page helpful?