Add Container field
This commit is contained in:
42
routes/channels.php
Normal file
42
routes/channels.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Broadcast;
|
||||
use App\Models\SupportTicket;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Broadcast Channels
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
Broadcast::channel('ticket.{ticketId}', function ($user, $ticketId) {
|
||||
|
||||
\Log::info('🔐 Broadcasting Auth Check', [
|
||||
'ticketId' => $ticketId,
|
||||
'user_id' => $user->id ?? 'NULL',
|
||||
'user_table' => method_exists($user, 'getTable') ? $user->getTable() : 'unknown',
|
||||
'user_class' => get_class($user)
|
||||
]);
|
||||
|
||||
$ticket = SupportTicket::find($ticketId);
|
||||
|
||||
if (!$ticket) {
|
||||
\Log::warning('❌ Ticket not found', ['ticketId' => $ticketId]);
|
||||
return false;
|
||||
}
|
||||
|
||||
// ✅ Admin/Staff Check (Session Auth)
|
||||
if (get_class($user) === 'App\Models\Admin') {
|
||||
\Log::info('✅ Admin authorized for ticket', ['admin_id' => $user->id]);
|
||||
return true;
|
||||
}
|
||||
|
||||
// ✅ User Check (JWT Auth - must own ticket)
|
||||
if (get_class($user) === 'App\Models\User' && $ticket->user_id === $user->id) {
|
||||
\Log::info('✅ User authorized for own ticket', ['user_id' => $user->id]);
|
||||
return true;
|
||||
}
|
||||
|
||||
\Log::warning('❌ Authorization failed');
|
||||
return false;
|
||||
});
|
||||
Reference in New Issue
Block a user