0

我正在建立一个带有实时通知的网站。但是我无法使用 Laravel Echo 收听通知。我不明白为什么它不起作用。

聆听

this.$echo.private('App.User.' + this.user.id)
    .notification(notification => {
        console.log(notification);
    });

通知:

user->notify(new \App\Notifications\SomeoneRepliedYourPikir([
        'pikir_id' => request()->get('pikir_id'),
        'username' => request()->user()->username
    ]));

渠道:

Broadcast::channel('App.User.{id}', function ($user, $id) {
    return (int) $user->id === (int) $id;
});

我想我粘贴了所有必要的东西来了解我的情况。其他事情都很好,比如存在渠道。

我的 Laravel-echo-server.json

{
"authHost": "http://pikirler.dev",
"authEndpoint": "/broadcasting/auth",
"clients": [
    {
        "appId": "2051a3c22fdd8a43",
        "key": "500c9e2934af4f6e93892f56abfcdc27"
    }
],
"database": "redis",
"databaseConfig": {
    "redis": {
        "port": "6379",
        "host": "127.0.0.1"
    },
    "sqlite": {
        "databasePath": "/database/laravel-echo-server.sqlite"
    }
},
"devMode": true,
"host": "pikirler.dev",
"port": "6001",
"protocol": "http",
"socketio": {},
"sslCertPath": "",
"sslKeyPath": ""}
4

1 回答 1

-1

将此功能放在您的用户模型中。它将正常工作

public function receivesBroadcastNotificationsOn()
    {
        return 'App.User.'.$this->id;
    }
于 2020-01-06T03:22:39.853 回答