I am trying to switch notifications to use queue. I have implemented the ShouldQueue interface and added the Queueable trait to the notification class.
No matter which QUEUE_CONNECTION
I use, the job is processed successfully but the mail doesn't get sent.
Now the same mail gets sent and delivered successfully when I comment out the interface and the trait.
I added \Log::info()
to the constructor and the toMail()
method of the notification class. I can see the log message from the constructor in the logs but not that of the toMail()
method.
I created a job to send the notification and added log messages to job's handle()
method. One before and one after the notification calling statements. When the notification class does not enable queue (the interface and trait), the notification gets sent and delivered.
But when I enabled queueing, it does not send mail. I get the log message from the notification class constructor but not from the toMail()
method.
I upgraded this code from Laravel 11
I have tested this with MailPit and a third-party transaction mail service
Steps To Reproduce:
Create a new Laravel project, create a notification class with queue enabled, and test.
Laravel Version: 12.21
PHP Version: 8.3
EDIT: The worker is properly set up and running. Also, it doesn't work regardless of what queue connection is used
I have found what was missing.
Queued notification will not work if the notifiable model is not persisted. This is not an issue when ShouldQueue is not implemented.