I am trying to send notification email + database notification to multiple users. I am experiencing this strange behavior with laravel queue, it sends database notification perfectly but do not send email. And If I remove the queue it works just fine, both the database notification as well as email are being received.
Note: Queue gets processed successfully.
Laravel 7
QUEUE_CONNECTION=database
Notificaion:
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class CommentOnTask extends Notification implements ShouldQueue
{
use Queueable;
private $data;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['database', 'mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action', url('/'))
->line('Thank you for using our application!');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
/**
* Get the database representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toDatabase($notifiable)
{
return [
'body' => $this->data['body'],
];
}
}
Controller:
<?php
.
.
.
$members = $task->users;
$members = $members->merge($task->followers);
Notification::send($members, new CommentOnTask($data));