gpt4 book ai didi

laravel - 发布http ://localhost:8000/broadcasting/auth 403 (Forbidden)/for customer service chat where i only need auth for admins

转载 作者:行者123 更新时间:2023-12-02 10:58:16 26 4
gpt4 key购买 nike

如何为管理员使用广播/身份验证而不为普通用户使用广播/身份验证,并且两者仍然可以互相聊天?

//广播服务提供者

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

关于laravel - 发布http ://localhost:8000/broadcasting/auth 403 (Forbidden)/for customer service chat where i only need auth for admins,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57671048/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com