我看不到,无法找出 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。
有谁知道为什么这现在可以工作了?
最佳答案
实际广播是一个Job。查看你的 Laravel 作业队列。当作业通过 php artisan queue:work
执行时,broadcastOn()
方法将触发。
关于php - Laravel 事件广播未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38485326/