php - Laravel 事件广播未触发

标签 php laravel events 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。

有谁知道为什么这现在可以工作了?

最佳答案

实际广播是一个Job。查看你的 Laravel 作业队列。当作业通过 php artisan queue:work 执行时,broadcastOn() 方法将触发。

关于php - Laravel 事件广播未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38485326/

相关文章:

php - laravel 5.5 页面由于不活动而过期。请刷新并重试

CSS 位置和不透明度样式干扰悬停和点击事件

php - xampp下php中的命名空间

javascript - ASK - jquery datepicker - 在文本输入中保留选定的日期

mysql - 如何在 webform 中打开时锁定 MySQL 资源并在关闭/完成编辑时释放

php - Laravel 查询生成器 - 从传统 SQL 迁移

javascript - jQuery在点击事件打开新选项卡时模拟ctrl + click

mysql事件不起作用

php - 如何使用 HTTP POST 使用 HTML 和 PHP 选择和上传多个文件?

javascript - symfony2如何通过javascript访问twig路径