php - laravel 广播多后卫
问题描述
我有以下为我的应用程序定义的身份验证保护,admins
等等designers
。customers
默认保护是designer guard
.
我希望每个guard
人都有自己的private channel
。所以我在我的 channel.php 中定义它,每个条目都有多个条目,如下所示
Broadcast::channel('private.admins.{id}', function ($admin, $id) {
Log::info($admin);
//logging the admin
});
但这总是binding
在default guard
课堂上,所以我的问题是我如何告诉它在这里使用Admin model
。我无法在任何地方找到它。所以你能指出我正确的方向吗
其实我希望每个guard
人都有自己的private channel
。
解决方案
尝试更改BroadcastServiceProvider
文件app\Providers\BroadcastServiceProvider.php
每个警卫的不同广播身份验证端点
public function boot()
{
//Broadcast::routes();
//match any of the 3 auth guards
Broadcast::routes(['middleware' => ['web','auth:admins,designers,customers']]);
require base_path('routes/channels.php');
}
现在在 channels.php
Broadcast::channel('admins.channel.{id}', function ($model, $id) {
return $model->id === $id && get_class($model) === 'App\Admin';
});
Broadcast::channel('designers.channel.{id}', function ($model, $id) {
return $model->id === $id && get_class($model) === 'App\Designer';
});
Broadcast::channel('customers.channel.{id}', function ($model, $id) {
return $model->id === $id && get_class($model) === 'App\Customer';
});
推荐阅读
- python - 如果 SQL 查询不带任何数据,则在 python 中退出循环
- image - 在 GUI 中实现图像
- c# - 如何通过 webapi 传递字符串列表并获得没有这些字符串的结果?
- python-3.x - 如何将字符串的一部分表示为 HTML 中的图像?
- c# - 如何为服务器上的每个用户运行计时器
- r - Shinydashboard 标题中的自动换行或换行
- c# - SaveChanges 不适用于 JsonResult 方法(更新信息)
- laravel - 向 Laravel 集合添加新属性
- c# - 在 Windows 服务和 Azure WebJob 之间利用单一代码库的方法
- dart - 如何创建一个内部包含三个单独按钮的自定义容器