Files
Kent-logistics-Laravel/routes/channels.php
2026-02-17 14:44:47 +05:30

43 lines
1.3 KiB
PHP

<?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;
});