From 61326ef0dd570f1d229d58ed686b691a6e11ea89 Mon Sep 17 00:00:00 2001 From: delicatacurtis Date: Tue, 20 Jan 2026 20:43:19 +0000 Subject: [PATCH] Update channels.php --- routes/channels.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/routes/channels.php b/routes/channels.php index c5af0079..5454a671 100644 --- a/routes/channels.php +++ b/routes/channels.php @@ -1,6 +1,8 @@ (int) $user->id === (int) $id); + +// Channel for ResearchSpace real-time updates. +// A user may listen if they are the owner or a collaborator on the space. +Broadcast::channel('research-space.{id}', function ($user, $id) { + try { + $space = ResearchSpace::find($id); + if (! $space) { + return false; + } + if ($space->owner_id === $user->id) { + return true; + } + + return ResearchSpaceCollaborator::where('research_space_id', $id) + ->where('user_id', $user->id) + ->exists(); + } catch (\Throwable $e) { + return false; + } +});