Laravel 5.2事件广播没有触发

时间:2016-07-20 15:57:04

标签: php events laravel-5 redis

我无法看清楚为什么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。

有谁知道为什么现在可以这样做?

1 个答案:

答案 0 :(得分:2)

实际广播是一项工作。查看Laravel作业队列。当作业通过broadcastOn()执行时,{{1}}方法将会触发。