In this WS tutorial, this tutor is building a chat app.
I am skeptical about his code here:
- https://github.com/acadea/course_laravel_api_server_livepost/blob/master/app/Events/ChatMessageEvent.php#L40
return new PresenceChannel('presence.chat.1'); - https://github.com/acadea/course_laravel_api_server_livepost/blob/master/routes/channels.php#L20-L21
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?