#Laravel Websockets question

3 messages · Page 1 of 1 (latest)

mild otter
#

In this WS tutorial, this tutor is building a chat app.

I am skeptical about his code here:

Broadcast::channel('presence.chat.{id}', function ($user, $id){
    return $user;
});

He hard-coded the channel name to presence.chat.1, and then instead of doing something like

Broadcast::channel('presence.chat.{id}', function ($user, $id){
    if ($id == $user->id) return $user;
    else return false;
});

He just returned the user without any checks.

Wouldn't it be better to just do it this way?:
PresenceChannel('presence.chat');

Broadcast::channel('presence.chat', function ($user){
    return $user;
});

PS: even if there is a check like if ($id == $user->id) return $user;, it still wouldn't be ideal, because messages can only be sent to user of ID=1

Am I right to think this way?

mild otter
#

cc @daring vessel

mild otter
#

I thought you would know