php - 管理员守卫中的laravel广播
问题描述
在我的 laravel 网站中,我们有两个警卫admin
,customer
这个警卫的表格是 ->customer table
和admin table
。
我想通过
这是我在 .js 文件中的代码将通知从 a 发送到customer
管理员守卫admin
laravel broadcasting
server.js 文件:
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':6001',
});
* i have a admin by id=2 *
Echo.private('App.Models.Admin.2')
.notification((notification) => {
console.log(notification.type);
});
并进入客户警卫:
\Notification::send(Admin::find(2) , new SimpleAlert('hey bro'));
简单警报.php:
public function toBroadcast($notifiable)
{
return new BroadcastMessage([
'message' => $this->message,
'type' => 'broadcast'
]);
}
所以,我启动 laravel-echo-server 并打开两个谷歌浏览器标签,一个用于admin guard
另一个用于customer guard
并登录到两个警卫。
控制台没有错误。没有错误customer sending notification
,但 `admin 没有收到通知。
问题:
当我进入时 laravel-echo-server 显示这个admin guard
客户端无法通过身份验证,获得 HTTP 状态 403
请帮帮我。
解决方案
您可以做的是在routes/channels.php
. 试试这个
Broadcast::channel('App.Models.Admin.{userId}', function ($user, $userId) {
return $user->id === $userId;
});
推荐阅读
- php - 正则表达式不能限制搜索范围
- sql - 当查询不返回结果时 BigQuery INSERT INTO
- swift - 如何通过单击表格视图中的按钮来添加其他文本字段
- javascript - Android 5.1 设备重置后 Cordova 应用程序未捕获的 SyntaxError
- reactjs - 如何在反应中处理 URL 参数
- ruby-on-rails - 即使未请求,选择查询也会在结果中添加 attr_encrypted 属性
- android - 打开图库并选择图像后,Android Toast 未显示
- node.js - 有没有办法使用 firebase admin sdk 的 ProjectManagement 服务从 Firebase 项目中删除 android 或 ios 应用程序?
- fetch - 有没有办法在服务工作者中导入或加载库?
- python-3.x - Python:使用 selenium 登录网站?