【发布时间】:2017-11-27 11:35:07
【问题描述】:
我正在构建一个带有实时通知的网站。但是我无法使用 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": ""}
【问题讨论】:
-
我们可以看看你的 laravel-echo-server.json 吗?
-
@Ohgodwhy 它正在加入频道并成功触发事件 BroadcastNotificationCreated,但在控制台中有任何内容
-
@Ohgodwhy 哦,我发现了我的愚蠢错误。我的错误是我将所有模型都移到了模型目录中,并且在 channels.php 中没有更改。愚蠢的错误花了我几个小时才解决:D
-
是的,这是一个非常常见的错误!很高兴你解决了。
-
我可以看看你的 channels.php 文件吗?无法更改名称空间。我还更改了模型目录,通知停止工作
标签: laravel real-time laravel-echo