【发布时间】:2016-07-20 15:57:03
【问题描述】:
我看不到为什么没有触发 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 端口。
有谁知道为什么这现在可行?
【问题讨论】: