I would like to send email notifications using the queue.
I have created the queue table and tracked all the documentation related to this topic but the notifications are sent without going through the queue.
In my controller:
Notification::send(User::role('team')->get(), new NewExchangeToCollaboratorNotification($user, $exchange, $firstMessage));
And my notification code is:
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Setting;
class NewExchangeToCollaboratorNotification extends Notification implements ShouldQueue
{
use Queueable;
protected $user; protected $exchange; protected $exchangeMessage; protected $replyToAddress;
public function __construct($user, $exchange, $exchangeMessage)
{
$this->user = $user;
$this->exchange = $exchange;
$this->exchangeMessage = $exchangeMessage;
$this->replyToAddress = Setting::get('MAIL_REPLY_TO_ADDRESS', env('MAIL_FROM_ADDRESS'));
}
public function via($notifiable)
{
return ['mail'];
}
public function toMail($notifiable)
{
return (new MailMessage)->view(
'emails.exchanges.new',
[
'user' => $this->user,
'exchangeMessage' => $this->exchangeMessage,
'exchange' => $this->exchange
]
) ->subject('New exchange: ' . $this->exchange->title)
->from(env('MAIL_FROM_ADDRESS'))
->replyTo($this->replyToAddress);
}
}
Are the notifications queueable? Is there something I'm doing wrong? Thank you for your answers:)
EDIT: Add delay does not work too.
$when = now()->addMinutes(10);
Notification::send(User::role('team')->get(), (new NewExchangeToCollaboratorNotification($user, $exchange, $firstMessage))->delay($when));
EDIT 2: No failed job
Make sure your.env is: QUEUE_CONNECTION=database
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.