Search code examples
phplaravellaravel-5.6laravel-echo

Laravel: How to specify returned data with a Broadcast?


I'm working with a Presence Channel and according to the docs, you can return a specific array of data of what you need. e.g. in this case, it's the id and name from the variable $user.

Broadcast::channel('chat', function ($user) {
    return ['id' => $user->id, 'name' => $user->name];
});

In my JS file I have

Echo.join(`chat`)
.here((users) => {
  console.log('users here: ',users);
})

The console.log() returns an array of all user data (like email addresses) instead of just the id and name that I specified in the Broadcast.

How can I only make it contain the id and name ?


Solution

  • I restarted the browser and it just started working as normal... odd. There seems to be some type of caching thing going on that is not within the browser but perhaps on the Pusher side of things.. I'm not sure.