Framework: Notification delay does not work?

Created on 27 Apr 2017  路  11Comments  路  Source: laravel/framework

  • Laravel Version: 5.4.*
  • PHP Version: 7.1
  • Database Driver & Version: All up to date

Description:

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?

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;
`}

All 11 comments

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!!

Was this page helpful?
0 / 5 - 0 ratings