Laravel 版本:5.5.*
PHP 版本:7.1.*
根据文档https://laravel.com/docs/5.5/notifications https://laravel.com/docs/5.5/notifications#notification-events订阅通知事件应该非常简单。我已按照文档中的步骤操作,但我的通知实现了ShouldQueue
并且他们没有正确填充事件侦听器。我想知道这个问题是否是在框架代码中 https://github.com/laravel/framework/blob/5.5/src/Illuminate/Notifications/NotificationSender.php.
请注意,在 github 框架(上面链接)中,new Events\NotificationSent($notifiable, $notification, $channel, $response)
仅从sendToNotifiable
函数,而该函数又只能从sendNow
功能。这send
函数本身,是这样的:
public function send($notifiables, $notification)
{
$notifiables = $this->formatNotifiables($notifiables);
if ($notification instanceof ShouldQueue) {
return $this->queueNotification($notifiables, $notification);
}
return $this->sendNow($notifiables, $notification);
}
也就是说,正如它给我读到的那样,该事件不会开火如果是以下情况if ($notification instanceof ShouldQueue) {
as queueNotification
从不触发事件侦听器。我假设它进入队列,然后需要重新触发事件,但我不认为这种情况会发生,因为我的NotificationSent
侦听器未填充any来自该类构造函数的数据。
事件服务提供者:
protected $listen = [
'Illuminate\Notifications\Events\NotificationSent' => [
'App\Listeners\NewNotificationListener',
],
新的通知监听器:
<?php
namespace App\Listeners;
use Illuminate\Notifications\Events\NotificationSent;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Jobs\SendEmailForNotifications;
use Illuminate\Support\Facades\Log;
class NewNotificationListener
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
public function handle(NotificationSent $event)
{
Log:info('Notification Listener:'.' '.var_dump($event));
SendEmailForNotifications::dispatch($event->notification)->delay(now()->addMinutes(10));
}
}
var_dump
这里是空的,我的日志中什么也没有,只是Notification Listener:
.
所以我的问题是,为什么会这样以及如何在利用队列的同时拥有一个通知事件侦听器,就像我需要做的那样。是我做错了什么还是框架的问题?