我无法看清楚为什么broadcastOn()没有触发。这是我的代码:
<?php
namespace App\Events;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class NotificationEvent extends Event implements ShouldBroadcast{
use SerializesModels;
/**
* Create a new event instance.
*
* @return void
*/
public $message;
public $user;
public function __construct($user_id,$message){
$this->user = $user_id;
$this->message = $message;
}
/**
* Get the channels the event should be broadcast on.
*
* @return array
*/
public function broadcastOn()
{
//var_dump("Sending event to:".'userNotifications.'.$this->user_id);
//return ['userNotifications.'.$this->user_id];
\Log::info("broadcast notification");
\Log::info($this->message);
return ['notifications'];
}
}
登录_construct有效,但是broadcastOn()中的日志记录不起作用。
我的.env文件设置为redis,Redis服务器已打开并侦听端口3001。
有谁知道为什么现在可以这样做?
答案 0 :(得分:2)
实际广播是一项工作。查看Laravel作业队列。当作业通过broadcastOn()
执行时,{{1}}方法将会触发。