0

I cannot change the channel name in the event class. Every change I make in the class is not loaded. (I am using laravel-websockets)

/app/Events/BroadcastingModelEvent

class BroadcastingModelEvent implements ShouldBroadcast
    {
        use Dispatchable, InteractsWithSockets, SerializesModels;
    
        public $message;
    
        public function __construct($message)
        {
            $this->message = $message;
        }
    
        public function broadcastOn()
        {
            return new Channel('test');
        }
    
    }

/routes/web.php:

Route::get('test', function () {
    event(new App\Events\BroadcastingModelEvent('Test'));
    return "Event has been sent!";
});

VueComponent

Echo.channel('test')
                .listen('BroadcastingModelEvent', (e) => {
                     console.log(e);
                });

So this code works, I receive the event in the console.log everything is ok.

But if I change return new Channel('something'); and Echo.channel('something') it stops working.

I tried php artisan route:clear, php artisan cache:clear, php artisan event:clear and nothing works.I stopped the php artisan websockets:serve process and restarted it. That class only works with the 'test' name I first gave and nothing else.

I cannot figure out where is it caching the class because any change I make in BroadcastingModelEvent is not reflected.

grimdbx
  • 175
  • 2
  • 12
  • you need to create channel in `channels.php` then in event you can use it – Kamlesh Paul Nov 23 '20 at 12:05
  • but with `test` name works without any entry in channels.php. Anyway I added `Broadcast::channel('something', function () { return true; });` still is not working. – grimdbx Nov 23 '20 at 12:36

1 Answers1

2

For anyone facing this issue, you need to restart the queue worker process when you edit the events.

grimdbx
  • 175
  • 2
  • 12