我正在建立一个具有实时通知的网站。但是我听不到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": ""}
将此功能放在您的用户模型中。它将起作用
public function receivesBroadcastNotificationsOn()
{
return 'users.'.$this->id;
}