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
的用途是什么?
答案 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