session()->getId(); if (!$sessionId) { return; } // Get the active guard from session (defaults to 'web') $activeGuard = $request->session()->get('active_guard', 'web'); // Get the authenticated user ID for the active guard $userId = \Illuminate\Support\Facades\Auth::guard($activeGuard)->id(); // If no user is authenticated on the active guard, fall back to default guard if (!$userId) { $userId = \Illuminate\Support\Facades\Auth::id(); } // Update both guard and user_id columns in the sessions table try { $updateData = ['guard' => $activeGuard]; // Only update user_id if we have one if ($userId) { $updateData['user_id'] = $userId; } DB::table(config('session.table', 'sessions')) ->where('id', $sessionId) ->update($updateData); } catch (\Exception $e) { // Silently fail - don't break the application if guard column doesn't exist yet // This can happen during migration or if the migration hasn't run } } }