我如何使用广播/auth管理,但不对正常的用户,但仍然可以互相聊天?
// BroadcastServiceProvider
public function boot()
{
Broadcast::routes();
require base_path('routes/channels.php');
}// Channels.php
Broadcast::channel('App.User.{id}', function ($user, $id) {
return (int) $user->id === (int) $id; });
Broadcast::channel('chat', function ($user) {
return $user; });// MessageSent事件
public function broadcastOn()
{
return new PresenceChannel('chat');
}我得到了这个错误: POST http://localhost:8000/broadcasting/auth 403 (禁止),但是当我从laravel (Echo.join('chat'))删除时,错误就会发生。
发布于 2020-02-18 14:30:16
你可以用Middleware实现这样的目标。
这句话来自laravel的官方网站:
中间件为过滤进入应用程序的HTTP请求提供了一种方便的机制。例如,Laravel包含一个中间件,用于验证应用程序的用户是否经过身份验证。如果未对用户进行身份验证,中间件将将用户重定向到登录屏幕。但是,如果对用户进行了身份验证,中间件将允许请求进一步进入应用程序。
从这个网站中完全读取
https://stackoverflow.com/questions/57671048
复制相似问题