Laravel Reverb + Echo naming convention.

 

 Echo listen() function relies on a very exact and weird naming convention, something to do with Namespaces:

If the php Event name is "ChatMessageSent" then Echo knows how to listen to that event as:

    Echo.private('chats').listen('ChatMessageSent', (e) => {
        console.log('New chat message', e);
    });

But if we have a broadcastAs() method in the event class:

    public function broadcastAs(): string
    {
        return 'chat.message.sent';
    }



Then Echo doesn't know how to listen to chat.message.sent event. Instead, you have to put a dot before the event name:

.chat.message.sent


Echo.private('chats').listen('.chat.message.sent', (e) => {
      console.log('New chat message', e);
});

 

 

Comments

Popular posts from this blog