POST http://localhost:8000/broadcasting/auth 403 (Forbidden) / 用于客户服务聊天,我只需要管理员授权
POST http://localhost:8000/broadcasting/auth 403 (Forbidden) / for customer service chat where i only need auth for admins
如何为管理员使用 broadcasting/auth 而不是为普通用户使用,并且仍然可以互相聊天?
// 广播服务提供商
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; });
// 消息发送事件
public function broadcastOn()
{
return new PresenceChannel('chat');
}
我收到此错误:POST http://localhost:8000/broadcasting/auth 403(禁止),但是当我从 laravel 中删除时 echo (Echo.join('chat' )) 出错了。
您可以在 laravel 中使用 Middleware
来实现这样的事情。
此引自laravel官网:
Middleware provide a convenient mechanism for filtering HTTP requests
entering your application. For example, Laravel includes a middleware
that verifies the user of your application is authenticated. If the
user is not authenticated, the middleware will redirect the user to
the login screen. However, if the user is authenticated, the
middleware will allow the request to proceed further into the
application.
完整阅读本文website
如何为管理员使用 broadcasting/auth 而不是为普通用户使用,并且仍然可以互相聊天?
// 广播服务提供商
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; });
// 消息发送事件
public function broadcastOn()
{
return new PresenceChannel('chat');
}
我收到此错误:POST http://localhost:8000/broadcasting/auth 403(禁止),但是当我从 laravel 中删除时 echo (Echo.join('chat' )) 出错了。
您可以在 laravel 中使用 Middleware
来实现这样的事情。
此引自laravel官网:
Middleware provide a convenient mechanism for filtering HTTP requests entering your application. For example, Laravel includes a middleware that verifies the user of your application is authenticated. If the user is not authenticated, the middleware will redirect the user to the login screen. However, if the user is authenticated, the middleware will allow the request to proceed further into the application.
完整阅读本文website