Skip to content

Commit fe1fb72

Browse files
Merge pull request #1417 from delicatacurtis/patch-39
Update channels.php
2 parents 188b5fa + 61326ef commit fe1fb72

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

routes/channels.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

33
use Illuminate\Support\Facades\Broadcast;
4+
use App\Models\ResearchSpace;
5+
use App\Models\ResearchSpaceCollaborator;
46

57
/*
68
|--------------------------------------------------------------------------
@@ -14,3 +16,23 @@
1416
*/
1517

1618
Broadcast::channel('App.Models.User.{id}', fn($user, $id): bool => (int) $user->id === (int) $id);
19+
20+
// Channel for ResearchSpace real-time updates.
21+
// A user may listen if they are the owner or a collaborator on the space.
22+
Broadcast::channel('research-space.{id}', function ($user, $id) {
23+
try {
24+
$space = ResearchSpace::find($id);
25+
if (! $space) {
26+
return false;
27+
}
28+
if ($space->owner_id === $user->id) {
29+
return true;
30+
}
31+
32+
return ResearchSpaceCollaborator::where('research_space_id', $id)
33+
->where('user_id', $user->id)
34+
->exists();
35+
} catch (\Throwable $e) {
36+
return false;
37+
}
38+
});

0 commit comments

Comments
 (0)