首页 > 解决方案 > laravel 广播多后卫

问题描述

我有以下为我的应用程序定义的身份验证保护,admins等等designerscustomers默认保护是designer guard.

我希望每个guard人都有自己的private channel。所以我在我的 channel.php 中定义它,每个条目都有多个条目,如下所示

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


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

});

但这总是bindingdefault guard课堂上,所以我的问题是我如何告诉它在这里使用Admin model。我无法在任何地方找到它。所以你能指出我正确的方向吗

其实我希望每个guard人都有自己的private channel

标签: phplaravelsocket.iobroadcast

解决方案


尝试更改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';
});

推荐阅读