Fix broadcasting channel authorization
This commit is contained in:
+7
-1
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Broadcast;
|
use Illuminate\Support\Facades\Broadcast;
|
||||||
|
use App\Models\Conversation;
|
||||||
|
|
||||||
Broadcast::channel('App.Models.User.{id}', function ($user, $id) {
|
Broadcast::channel('App.Models.User.{id}', function ($user, $id) {
|
||||||
return (int) $user->id === (int) $id;
|
return (int) $user->id === (int) $id;
|
||||||
@@ -8,8 +9,13 @@ Broadcast::channel('App.Models.User.{id}', function ($user, $id) {
|
|||||||
|
|
||||||
Broadcast::channel('chat.{conversationId}', function ($user, $conversationId) {
|
Broadcast::channel('chat.{conversationId}', function ($user, $conversationId) {
|
||||||
|
|
||||||
return \App\Models\Conversation::where('id', $conversationId)
|
return Conversation::where('id', $conversationId)
|
||||||
->whereHas('users', fn ($q) =>
|
->whereHas('users', fn ($q) =>
|
||||||
$q->where('user_id', $user->id)
|
$q->where('user_id', $user->id)
|
||||||
)->exists();
|
)->exists();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Broadcast::channel('chat.{conversationId}', function ($user, $conversationId) {return Conversation::where('id', $conversationId)->whereHas('users', function ($q) use ($user) {$q->where('user_id', $user->id);})->exists();});
|
||||||
|
|||||||
Reference in New Issue
Block a user