为了账号安全,请及时绑定邮箱和手机立即绑定

Laravel - 通知邮件 ShouldQueue 不起作用

Laravel - 通知邮件 ShouldQueue 不起作用

PHP
繁星淼淼 2023-05-12 15:51:02
我想使用队列发送电子邮件通知。我已经创建了队列表并跟踪了与该主题相关的所有文档,但通知是在不经过队列的情况下发送的。在我的控制器中:Notification::send(User::role('team')->get(), new NewExchangeToCollaboratorNotification($user, $exchange, $firstMessage));我的通知代码是:<?phpnamespace 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);    }}通知是否可以排队?我做错了什么吗? 谢谢您的回答 :)编辑:添加延迟也不起作用。$when = now()->addMinutes(10);Notification::send(User::role('team')->get(), (new NewExchangeToCollaboratorNotification($user, $exchange, $firstMessage))->delay($when));编辑 2:没有失败的工作
查看完整描述

1 回答

?
慕的地10843

TA贡献1785条经验 获得超8个赞

确保您的 .env 是: QUEUE_CONNECTION=database



查看完整回答
反对 回复 2023-05-12
  • 1 回答
  • 0 关注
  • 154 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信