简体   繁体   English

授权 Laravel Package 中的通道

[英]Authorize Channel in Laravel Package

I am developing a laravel package where i need to authorize a private channel.我正在开发一个 laravel package 我需要授权一个私人频道。

In my normal laravel project(not the package) everything is working fine:在我正常的 laravel 项目(不是包)中,一切正常:

Event SendMessage:事件发送消息:

public function broadcastOn()
{
    return new PrivateChannel('chat');
}

and in my route/channel.php i do as follows:在我的route/channel.php中,我执行以下操作:

Broadcast::channel('chat', function ($user) {
    return Auth::check();
});

But how can i authorize my chat channel inside my laravel package?但是我如何在我的 laravel package 中授权我的聊天频道?

In my laravel package the service provider has boot and register functions, as with routes/web.php i know we can register it but what to do with the channels?在我的 laravel package 中,服务提供者具有引导和注册功能,与routes/web.php一样,我知道我们可以注册它,但如何处理渠道? Can we register them?我们可以注册它们吗? i find no documentation regarding that Please help.我找不到有关此的文档请帮助。

I am using pusher server and with laravel echo.我正在使用推送服务器和 laravel 回声。

Hopefully you can understand my question.希望你能理解我的问题。 I just wanna know how can i authroize channel in my package.我只想知道如何在我的 package 中授权频道。

The answer to my own question is that We must uncomment a line from config/app.php which is:我自己的问题的答案是我们必须取消注释config/app.php中的一行:

     App\Providers\BroadcastServiceProvider::class,

I was struggling with the channels and it comes to the point that, we do not need to register the channels or broadcasting services in our package.我在频道上苦苦挣扎,以至于我们不需要在 package 中注册频道或广播服务。

They are by default globally enabled.默认情况下,它们是全局启用的。

So everything remains the same and just by uncommenting that i was able to authorize the private channel.所以一切都保持不变,只是通过取消注释我能够授权私人频道。

Hoepfully nobody gets into such trouble.希望没有人会遇到这样的麻烦。

Cheers.干杯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM