在事件监听器中,我向狗主人发送通知,如下所示:
$event->dogowner->notify(new DogWasWalkedNotification);
问题是因为在下面的通知中有两个通道database
/mail
设置,它们都被添加为“通知”队列中的排队作业,在构造函数中设置。相反,我想将下面的邮件通道添加到emails
队列中,而不是“通知”构造函数中的默认设置。
知道如何让以下通知仅将邮件通道添加MailMessage
到emails
队列而不将database
通道添加到队列吗?(即使这意味着删除构造函数onQueue
)
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use App\Events\DogWasWalked;
class DogWasWalkedNotification extends Notification implements ShouldQueue
{
use Queueable;
protected $event;
public function __construct(DogWasWalked $event) {
$this->event = $event;
// This is what creates 2 queued jobs (one per channel)
$this->onQueue('notifications');
}
public function via($notifiable) {
return ['database', 'mail'];
}
public function toArray($notifiable) {
return [
'activity' => 'Dog was walked!',
'walkername' => $this->event->walkername
];
}
public function toMail($notifiable) {
// How to set the queue name for
// this channel to 'emails'
return (new MailMessage)
->line('Dog was walked!');
}
}