diff --git a/app/Http/Controllers/Auth/AuthenticatedSessionController.php b/app/Http/Controllers/Auth/AuthenticatedSessionController.php index 613bcd9..eb0f8cb 100644 --- a/app/Http/Controllers/Auth/AuthenticatedSessionController.php +++ b/app/Http/Controllers/Auth/AuthenticatedSessionController.php @@ -8,6 +8,7 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\View\View; +use Jenssegers\Agent\Agent; class AuthenticatedSessionController extends Controller { @@ -28,6 +29,24 @@ public function store(LoginRequest $request): RedirectResponse $request->session()->regenerate(); + $user = Auth::user(); + + // Get device and browser information using Agent + $agent = new Agent(); + $device = $agent->device(); + $browser = $agent->browser(); + $browserVersion = $agent->version($browser); + + $user->activity()->create([ + 'activity' => 'login', + 'description' => 'User ' . $user->name . ' logged in', + 'device' => $device, + 'browser' => $browser . ' ' . $browserVersion, + 'ip' => $request->ip(), + 'user_agent' => $request->userAgent(), + ]); + + return redirect()->intended(route('dashboard', absolute: false)); } @@ -36,6 +55,21 @@ public function store(LoginRequest $request): RedirectResponse */ public function destroy(Request $request): RedirectResponse { + $user = Auth::user(); + $agent = new Agent(); + $device = $agent->device(); + $browser = $agent->browser(); + $browserVersion = $agent->version($browser); + + $user->activity()->create([ + 'activity' => 'logout', + 'description' => 'User ' . $user->name . ' logged out', + 'device' => $device, + 'browser' => $browser . ' ' . $browserVersion, + 'ip' => $request->ip(), + 'user_agent' => $request->userAgent(), + ]); + Auth::guard('web')->logout(); $request->session()->invalidate(); diff --git a/resources/views/livewire/user-show.blade.php b/resources/views/livewire/user-show.blade.php index b889db9..7da180c 100644 --- a/resources/views/livewire/user-show.blade.php +++ b/resources/views/livewire/user-show.blade.php @@ -60,7 +60,7 @@

Joined {{ $user->created_at->diffForHumans() }}

-

Last seen ...

+

Last seen ...