laravel广播的多重卫兵 [英] laravel broadcasting for multiple guard

查看:55
本文介绍了laravel广播的多重卫兵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下为我的应用程序 admins designers customers 等定义的身份验证防护措施.默认的防护措施是设计师后卫.

I have the below auth guards that is defined for my app admins, designers, customers and etc. the default guard is the designer guard.

我希望每个 guard 都有自己的私有频道.因此,我在channel.php中定义了它,每个条目都有多个条目,如下所示:

I want every guard to have his own private channel. So I am defining it in my channel.php with multiple entries for each like below

Broadcast::channel('private.admins.{id}', function ($admin, $id) {


    Log::info($admin);
    //logging the admin

});

但这总是与默认警卫类进行绑定,所以我的问题是如何告诉我在这里使用 Admin模型.我在任何地方都找不到.那么你能指出我正确的方向吗?

But this is always binding with default guard class so my question is how do I tell that to use here Admin model. I am unable to find it anywhere. So can you point me in to right direction

实际上,我希望每个 guard 都有自己的私有频道.

Actually I want every guard to have his own private channel.

推荐答案

尝试在 BroadcastServiceProvider 文件 app \ Providers \ BroadcastServiceProvider.php

每个警卫的广播授权端点不同

Different broadcast auth end point for each guards

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中

Now in 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';
});

这篇关于laravel广播的多重卫兵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆