Skip to content

Commit

Permalink
channels authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
aothyab committed Jun 25, 2024
1 parent 50f70c5 commit 1a48807
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/routes/channels.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
use Corals\User\Transformers\API\SimpleUserPresenter;
use Illuminate\Support\Facades\Broadcast;

Broadcast::channel('messages.{user}', function (User $user) {
return true;
Broadcast::channel('messages.{user}', function (User $authUser, User $user) {
return $authUser->id === $user->id;
});

Broadcast::channel('online', function (User $user) {
return (new SimpleUserPresenter)->present($user)['data'];
});

Broadcast::channel('openedDiscussion.{discussion}', function (User $user, Discussion $discussion) {
return true;
return $discussion->participations()->where([
'messaging_participations.participable_type' => getMorphAlias($user),
'messaging_participations.participable_id' => $user->id,
])->exists();
});

0 comments on commit 1a48807

Please sign in to comment.