Laravel 5.5 - 通知通道不同的队列名称?

时间:2018-03-19 22:52:51

标签: laravel laravel-5 laravel-5.5 laravel-queue laravel-notification

在事件监听器中,我向狗主人发送通知,如下所示:

$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!');

    }
}

0 个答案:

没有答案
相关问题