Laravel-当我们可以在频道中对用户进行身份验证时,广播/身份验证有什么用?

时间:2018-12-12 11:39:19

标签: laravel authentication broadcast

class BroadcastServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Broadcast::routes();

        require base_path('routes/channels.php');
    }
}

Broadcast::routes()require base_path('routes/channels.php')中使用此代码return (int) $user->user_id === (int) $userId;对用户进行身份验证时,routes/channels.php的用途是什么?

1 个答案:

答案 0 :(得分:1)

  

谢天谢地,Laravel使得轻松定义响应路径   频道授权请求。在BroadcastServiceProvider中   包含在Laravel应用程序中,您将看到对   Broadcast::routes方法。此方法将注册   /broadcasting/auth处理授权请求的途径:

Broadcast::routes();将注册所需的身份验证基本路由。因此,例如,当您使用Laravel Echo时,它将把认证请求发送到/broadcasting/auth

  

默认情况下,Echo将使用/broadcasting/auth端点进行授权   频道访问。但是,您可以指定自己的授权   通过将authEndpoint配置选项传递给您的Echo来终结点   实例:

window.Echo = new Echo({ broadcaster: 'pusher', key: 'your-pusher-key', authEndpoint: '/custom/endpoint/auth' });

来源:https://laravel.com/docs/5.7/broadcasting#defining-authorization-routes