在事件监听器中,我向狗主人发送通知,如下所示:
$event->dogowner->notify(new DogWasWalkedNotification);
问题是因为在下面的通知中设置了两个频道database
/ mail
,他们两者都被添加为排队作业'notifications'队列,在构造函数中设置。相反,我想将下面的邮件通道添加到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!');
}
}