POST http:// localhost:8000 / broadcasting / auth 403(禁止)/用于客户服务聊天,其中我仅需要管理员的auth

问题描述 投票:3回答:1
我该如何为管理员使用广播/身份验证,而不是普通用户,仍然可以彼此聊天?

// 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'); }

我收到此错误:POSThttp://localhost:8000/broadcasting/auth403(禁止),但是当我从laravel回声(Echo.join('chat'))中删除时,该错误消失了。
laravel authentication chat broadcast
1个回答
1
投票
您可以使用laravel中的Middleware实现此类操作。

此报价来自laravel的官方网站:

中间件提供了一种方便的机制来过滤HTTP请求输入您的应用程序。例如,Laravel包含一个中间件验证您的应用程序的用户已通过身份验证。如果用户未通过身份验证,中间件会将用户重定向到登录屏幕。但是,如果用户通过了身份验证,中间件将允许请求进一步处理申请。

从此website完成读取

© www.soinside.com 2019 - 2024. All rights reserved.