Laravel 5.5 + pusher + echo

484 views Asked by At

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??

1

There are 1 answers

1
hamza On

in your event class you should implement ShouldBroadcast or ShouldBroadcastNow (in case you are not using queues).