Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel Socket.io,Redis事件正在广播,但未在客户端显示_Laravel_Redis_Socket.io - Fatal编程技术网

Laravel Socket.io,Redis事件正在广播,但未在客户端显示

Laravel Socket.io,Redis事件正在广播,但未在客户端显示,laravel,redis,socket.io,Laravel,Redis,Socket.io,在我的laravel.log中,我可以看到该事件正在频道上广播,即 [2018-08-30 13:41:27] local.INFO: Broadcasting [App\Events\NewRating] on channels [rating] with payload: { "music": { "id": 42, "name": "1535368873_admin.mp3", "path": "public\/music\/1535

在我的laravel.log中,我可以看到该事件正在频道上广播,即

[2018-08-30 13:41:27] local.INFO: Broadcasting [App\Events\NewRating] on channels [rating] with payload:
{
    "music": {
        "id": 42,
        "name": "1535368873_admin.mp3",
        "path": "public\/music\/1535368873_admin.mp3",
        "rating": 53,
        "user_id": 4,
        "created_at": "2018-08-27 11:21:13",
        "updated_at": "2018-08-27 11:21:13",
        "is_last_played": 1,
        "is_now_playing": 0,
        "location_id": 1
    },
    "socket": null
}  
[18:41:24] - VX9bkHqs-QHRv3MvAAAC joined channel: rating
到目前为止,我知道我已经按照要求完成了所有工作。我的redis服务器正在运行。laravel-echo-server正在运行,它正在加入我的频道,即

[2018-08-30 13:41:27] local.INFO: Broadcasting [App\Events\NewRating] on channels [rating] with payload:
{
    "music": {
        "id": 42,
        "name": "1535368873_admin.mp3",
        "path": "public\/music\/1535368873_admin.mp3",
        "rating": 53,
        "user_id": 4,
        "created_at": "2018-08-27 11:21:13",
        "updated_at": "2018-08-27 11:21:13",
        "is_last_played": 1,
        "is_now_playing": 0,
        "location_id": 1
    },
    "socket": null
}  
[18:41:24] - VX9bkHqs-QHRv3MvAAAC joined channel: rating
这是我订阅频道和收听活动的地方

window.app = new Vue({
        el: '#app',

        beforeMount: function () {
        alert("asdas");
        this.joinPublicChatChannel();
        },

        methods: {
        joinPublicChatChannel: function () {
            Echo.channel('rating').listen('App\\Events\\NewRating', (event) => {
                console.log("Event fired!"); //This doesnt work
            });
            }
        }
});
这是我的活动课

class NewRating implements ShouldBroadcastNow
{ 
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $music;
    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct(Music $music)
    {
        $this->music=$music;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return Channel|array
     */
    public function broadcastOn()
    {
        return new Channel('rating');
    }
}
这是我的环境文件

APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=laravel_restaurant
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=redis
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=
不知道背后的原因:/

更新

刚刚清除了所有的缓存,现在我在laravel echo服务器控制台中得到了这个


没关系,我跑了这个:。刚刚清理了缓存然后进去了

Echo.channel('rating').listen('App\\Events\\NewRating', (event) => {
            console.log("Event fired!"); //This doesnt work
        });

我使用了NewRating而不是App\\Events\\NewRating

您可以在事件文件中使用此选项:

public function broadcastAs()
{
    return 'NewRating';
}