Skip to content

useEcho not working with Broadcast Notifications #440

Closed
@clarkmcc

Description

@clarkmcc

Echo Version

2.1.4

Laravel Version

12.14.1

PHP Version

8.4

NPM Version

10.9.2

Database Driver & Version

No response

Description

I'm trying to use Broadcast Notifications. I can see the following event in my browser's websocket stream

{
  "event": "Illuminate\\Notifications\\Events\\BroadcastNotificationCreated",
  "data": "{\"description\":\"foobar\",\"id\":\"3b4e5c99-65bd-44f8-b5d7-765bbe5bebea\",\"type\":\"activity_posted\"}",
  "channel": "private-App.Models.User.56"
}

However, I'm struggling to find the right incantation to get this event to come through useEcho. I've tried the following, but no event is ever logged.

useEcho(`App.Models.User.${auth.user.id}`, '.Illuminate\\Notifications\\Events\\BroadcastNotificationCreated', (event) => {
    console.log(event);
  });
useEcho(`App.Models.User.${auth.user.id}`, 'Illuminate\\Notifications\\Events\\BroadcastNotificationCreated', (event) => {
    console.log(event);
  });
useEcho(`App.Models.User.${auth.user.id}`, 'Illuminate.Notifications.Events.BroadcastNotificationCreated', (event) => {
    console.log(event);
  });
useEcho(`App.Models.User.${auth.user.id}`, 'activity_posted', (event) => {
    console.log(event);
  });

What is the correct way to subscribe to Broadcast Notifications? If there isn't an issue here, at the very least, maybe we can bolster the React documentation for subscribing to these events.

Steps To Reproduce

I'm hoping that maybe there's a simple answer to my question above. If not, I can work on creating a repro.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions