Home > OS >  Laravel-websocket. Can't fire event
Laravel-websocket. Can't fire event

Time:10-20

I'm trying to make real-time laravel app with beyondcode's laravel-websockets, and pusher-php-server following this manual. But i didnt specify the version of the pusher/pusher-php-server package because it requires an outdated php version.

I created "NewTrade" event implements "ShouldBroadcastNow" Then I triggered the event by running the following with tinker:

event (new \App\Events\NewTrade('test'))

It returns:

>>> event (new \App\Events\NewTrade('test'));
=> [
    null,
]

"broadcastOn" method of NewTrade event fired

    public function broadcastOn()
    {

        $test = new \App\Models\Test();
        $test->title = "event";
        $test->save();

        return new Channel('trades');
    }

I see this in the database, new records are being created in the Test table. But in websockets dashboard ( http://127.0.0.1:8000/laravel-websockets ) no info about this event.

Help pls(( What am I doing wrong?

CodePudding user response:

i didnt specify the version of the pusher/pusher-php-server package because it requires an outdated php version.

I made the same mistake and ended up struggling with this issue for hours.

Apparently, the latest version of pusher-php-server is not compatible with laravel-websockets.

The following workaround posted by github user mankms fixed it for me:

# run this command from the root directory of your Laravel app
composer require pusher/pusher-php-server:7.0.2

CodePudding user response:

Maybe you haven't configured app (.env file) properly.

Heres official laravel-websockets docs https://beyondco.de/docs/laravel-websockets/getting-started/introduction

For Laravel docs on broadcasting and websockets you can checkout https://laravel.com/docs/9.x/broadcasting#introduction

Have you ran:

php artisan websockets:serve

?

Also, I was struggling hard to setup this package with Laravel Sail (Docker), ended up switching to Soketi instead because for what ever reason, events were never caught, just like issue you are having. So most likely your problem is configuration related.

  • Related