【发布时间】:2018-06-23 09:43:57
【问题描述】:
在我的 laravel 网站中,我们有两个守卫 admin 和 customer 这个守卫的表格是 ->customer table 和 admin table。
我想通过laravel broadcasting 将通知从customer 发送到admin
这是我将 .js 文件中的代码放入 admin guard
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'));
SimpleAlert.php:
public function toBroadcast($notifiable)
{
return new BroadcastMessage([
'message' => $this->message,
'type' => 'broadcast'
]);
}
所以,我启动 laravel-echo-server 并打开两个谷歌浏览器选项卡,一个用于 admin guard,另一个用于 customer guard,然后登录到这两个守卫。
控制台没有错误。 customer sending notification 没有错误,但 `admin 没有收到通知。
问题:
当我进入admin guard时,laravel-echo-server 会显示这个
客户端无法通过身份验证,得到 HTTP 状态 403
请帮帮我。
【问题讨论】:
-
你需要在
channels路由中授权App.Models.Admin.2检查这个laravel.com/docs/5.6/broadcasting#authorizing-channels
标签: php laravel socket.io broadcast