File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 11<?php
22
33use Illuminate \Support \Facades \Broadcast ;
4+ use App \Models \ResearchSpace ;
5+ use App \Models \ResearchSpaceCollaborator ;
46
57/*
68|--------------------------------------------------------------------------
1416*/
1517
1618Broadcast::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+ });
You can’t perform that action at this time.
0 commit comments