From ab9c5211ba456a981d77083c06d5664676ad5f27 Mon Sep 17 00:00:00 2001 From: Anthony Rappa Date: Thu, 28 Mar 2024 20:37:47 -0400 Subject: [PATCH 1/2] Revert "Merge pull request #100 from mazur-adam/patch-1" This reverts commit 1621f54ed3034e52e5bfb95878191b98c0ae0efc, reversing changes made to bdedfee70f9cd885d83e602f5a16655fab1e8a93. --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 755ec30..6e481db 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,6 @@ [![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/rappasoft/laravel-authentication-log/Check%20&%20fix%20styling?label=code%20style)](https://github.com/rappasoft/laravel-authentication-log/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain) [![Total Downloads](https://img.shields.io/packagist/dt/rappasoft/laravel-authentication-log.svg?style=flat-square)](https://packagist.org/packages/rappasoft/laravel-authentication-log) -### Enjoying this package? [Buy me a beer 🍺](https://www.buymeacoffee.com/rappasoft) - Laravel Authentication Log is a package which tracks your user's authentication information such as login/logout time, IP, Browser, Location, etc. as well as sends out notifications via mail, slack, or sms for new devices and failed logins. ## Documentation, Installation, and Usage Instructions From 75ce9e93a83580f7cf47a0a86133da47c4f18569 Mon Sep 17 00:00:00 2001 From: Jim Winstead Date: Sat, 1 Feb 2025 13:04:46 -0800 Subject: [PATCH 2/2] fix: Create new log via User->authentications()->create() It is possible to use a custom `AuthenticationLog` by overriding the `authentications()` and `latestAuthentication()` methods from the `AuthenticationLoggable` trait, except for this listener which tries creates a new `AuthenticationLog` directly. By going through the User model, we will create an object of the correct (custom) class. This fixes the specific problem of a custom `AuthenticationLog` model that uses the `\Illuminate\Database\Eloquent\Concerns \hasUlids` trait not being successfully created here because it fails to generate the id. --- src/Listeners/LogoutListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Listeners/LogoutListener.php b/src/Listeners/LogoutListener.php index 305b560..ad52396 100644 --- a/src/Listeners/LogoutListener.php +++ b/src/Listeners/LogoutListener.php @@ -41,7 +41,7 @@ public function handle($event): void $log = $user->authentications()->whereIpAddress($ip)->whereUserAgent($userAgent)->orderByDesc('login_at')->first(); if (! $log) { - $log = new AuthenticationLog([ + $log = $user->authentications()->create([ 'ip_address' => $ip, 'user_agent' => $userAgent, ]);