I am trying to make a mail Notification with delay.
But it seems email has been sent out immediately.
I have php artisan queue:worker running. and QUEUE_DRIVER=database
I run $message->recipient->notify((new MessageEmailNotification($message))->delay($when));
in controller
in MessageEmailNotification
public function toMail($notifiable)
{
if ($this->message->isUnread()) {
return (new MailMessage)->line('Hello!');
}
}
How do I do it locally?
I'm unable to replicate your issue, please share a complete example. What's in your $when variable?
$when = Carbon::now()->addMinutes(10);
Same on the laravel docs
What was your solution @adrian999999 I seem to be running into the same issue.
So instead just delay the message, I use job to despatch it.
```
$this->dispatch(
(new MessageEmailNotification($message))->delay(Carbon::now()->addMinutes(5))
);
It's been a long time, I kind of lost the context of this solution. Hopefully this helps. @rvanbaalen
Notification delay doesn't work... I tried it and it didn't work for me either
Just tried using ->delay($when) and it isn't delaying the message, they are being sent immediately.
@joegarbett Use job(which sends the notification) dispatch delay, not notification delay.
I've also just worked it out, it's because I did not implement ShouldQueue
class NewWidget extends Notification implements ShouldQueue
{
use Queueable;
`}
thanks @joegarbett :+1:
Works for mi @joegarbett thanks a lot!!
Most helpful comment
I've also just worked it out, it's because I did not implement ShouldQueue
class NewWidget extends Notification implements ShouldQueue{use Queueable;`}