我正在尝试向多个用户发送通知电子邮件+数据库通知。我在laravel队列中遇到这种奇怪的行为,它完美地发送数据库通知,但不发送电子邮件。而且,如果我删除队列,它就可以正常工作,同时会收到数据库通知和电子邮件。
注意:队列已成功处理。
Laravel 7
QUEUE_CONNECTION=database
通知:
<?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'],
];
}
}
控制器:
<?php
.
.
.
$members = $task->users;
$members = $members->merge($task->followers);
Notification::send($members, new CommentOnTask($data));