lundi 19 mars 2018

Laravel 5.5 - Notification channels different queue names?

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

    }
}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2IzP33A
via IFTTT

Aucun commentaire:

Enregistrer un commentaire