This is my .env configuration
BROADCAST_DRIVER=pusher
PUSHER_APP_KEY=*******************
PUSHER_APP_SECRET=*********************
PUSHER_APP_ID=*****
This is my bootstrap.js
import Echo from 'laravel-echo'
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
key: '****************',
cluster: 'us2',
encrypted: true
});
This is my another js file
window.Echo.private('channel-1')
.listen('.server.created', function (e) {
alert(5)
});
This is my TestEvent file
public function broadcastOn()
{
return new PrivateChannel('channel-1');
}
public function broadcastAs()
{
return 'server.created';
}
This is my channels.php file
Broadcast::channel('channel-1', function ($user) {
return true;
});
Also I've created artisan command for fire event. in that file I have
event(new TestEvent());
It doesn't working without any error. What I should do??
in your event class you should implement ShouldBroadcast or ShouldBroadcastNow (in case you are not using queues).