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

10.2k views Asked by At

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?

1

There are 1 answers

12
cre8 On BEST ANSWER

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/