Search code examples
laravelbroadcastlaravel-7pusherauthorize

Authorize Channel in Laravel Package


I am developing a laravel package where i need to authorize a private channel.

In my normal laravel project(not the package) everything is working fine:

Event SendMessage:

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

and in my route/channel.php i do as follows:

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

But how can i authorize my chat channel inside my 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? Can we register them? i find no documentation regarding that Please help.

I am using pusher server and with laravel echo.

Hopefully you can understand my question. I just wanna know how can i authroize channel in my package.


Solution

  • The answer to my own question is that We must uncomment a line from config/app.php which is :

         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.

    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 it helps someone.

    Cheers.