laravel - Laravel echo 不监听私人通知回调。尝试了互联网上的所有内容
问题描述
我一直在调试我的 laravel Echo。
这是我的bootstrap.js
. 我没有使用 vue.js,我只是使用本地服务器localhost:8000
。
import EchoObj from 'laravel-echo';
window.Echo = new EchoObj({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
cluster: process.env.MIX_PUSHER_APP_CLUSTER,
encrypted: true
});
Echo.private('App.User.'+ loggedUser.id)
.notification((notification) => {
console.log(notification.type);
alert("listening")
})
我的 NotificationEvent 控制器:
Class NotificationEvent extends Notification{
public function via($notifiable)
{
return ['database', 'broadcast', 'mail'];
}
public function toBroadcast($notifiable){
return new BroadcastMessage([
"test" => "nesting"
]);
}
public function toArray($notifiable){}
public function toDatabase($notifiable){}
}
频道.php
Broadcast::channel('App.User.{id}', function ($user, $id) {
return (int) $user->id === (int) $id;
});
我知道为什么我的回声不起作用,因为每当我触发一个事件时,我都会检查推送的调试控制台,比如event(new NotificationEvent)
我在推送器上收到此消息
{
"test" : "nesting"
"id" : "ecc9912f-0ae2-44dc-b905-677f93bfc38b"
"type" : "App\\Notifications\\WorkflowUpdateNotification"
}
不过,我的公共频道运行良好。我的私人频道缺少什么。
解决方案
解决方案
由于某种原因,我的广播频道不适用于私人频道。因此,我必须准确指定要接收哪个频道通知。所以,我User
像这样更新模型并且它起作用了。
public function receivesBroadcastNotificationsOn()
{
return 'App.User.'.$this->id;
}
推荐阅读
- postgresql - INSERT 的分区表是否需要 autovacuum?
- python - 地点 关于 Pandas 多个条件
- python - 将多行合并为单行
- gitlab-ci - gitlab语法:这个配置中&default是什么意思
- c# - SAML2 SLO 与 OKTA 集成,命中格式错误的请求
- r - 在 r 中更新 mapboxer 代理
- javascript - 有没有办法在另一个文件中的组件树之外更改 redux 中的状态?
- arrays - 由用户输入设置的结构数组大小?
- treeview - 如何使节点图标树视图数据窗口更大
- pyspark - 如何在pyspark中为计数模型实现负二项式回归?