#StackBounty: #laravel #laravel-5 #laravel-5.5 #laravel-queue #laravel-notification Laravel 5.5 – Notification channels different queue…

Bounty: 50

In an event listener, I send a notification to a dog owner like this:

$event->dogowner->notify(new DogWasWalkedNotification);

The issue is since there are two channels database/mail set in the Notification below, they both get added as queued jobs on the ‘notifications’ queue, set in the constructor. Instead, I want to add the mail channel below to an emails queue instead of the default one set in the constructor of ‘notifications’.

Any idea how to have the following notification only add the mail channel MailMessage to an emails queue without adding the database channel to a queue at all? (even if that means removing the constructor onQueue)

<?php
namespace AppNotifications;

use IlluminateBusQueueable;
use IlluminateNotificationsNotification;
use IlluminateContractsQueueShouldQueue;
use IlluminateNotificationsMessagesMailMessage;
use AppEventsDogWasWalked;

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

    }
}


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.