Search code examples
laravelnotificationslaravel-5.3real-timebroadcasting

How can I set public channel without any authentication on broadcasting laravel?


I read here : https://laravel.com/docs/5.4/broadcasting#concept-overview

There explains that it can use public channel. But there is no example of how to use it

I just see an example of a private channel like this :

public function broadcastOn()
{
    return new PrivateChannel('user.'.$this->user->id);
}

I need a real example of public channel

I've tried searching, but I have not found it yet

Is there anyone can help?


Solution

  • if the Channel class is not used in your event, add this line:

    use Illuminate\Broadcasting\Channel;
    

    you have to return a Channel:

    public function broadcastOn()
    {
        return new Channel('myPublicChannelName');
    }
    

    An example can be found here: https://petericebear.github.io/starting-laravel-echo-20170303/