diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 37078bb..3a56a82 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,12 +13,12 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest, windows-latest] - php: [8.0, 8.1] - laravel: [9.*] + php: [8.1] + laravel: [10.*] stability: [prefer-lowest, prefer-stable] include: - - laravel: 9.* - testbench: 7.0 + - laravel: 10.* + testbench: 8.0 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 934719d..5e981d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to `Laravel Authentication Log` will be documented in this file. +### 3.0.0 - 2023-02-23 + +- Laravel 10 Support - https://github.com/rappasoft/laravel-authentication-log/pull/70 +- Use null safe/chaining operator - https://github.com/rappasoft/laravel-authentication-log/pull/57 +- Optimize Other Devices Logout Listener - https://github.com/rappasoft/laravel-authentication-log/pull/52 + ### 2.0.0 - 2022-02-19 ### Added diff --git a/README.md b/README.md index bda07ad..6e481db 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,13 @@ See the [documentation](https://rappasoft.com/docs/laravel-authentication-log) f :---------|:------------------ 8.x | 1.x 9.x | 2.x + 10.x | 3.x + +## Installation + +```bash +composer require rappasoft/laravel-authentication-log +``` ## Testing diff --git a/composer.json b/composer.json index 49bf6e5..9acf43a 100644 --- a/composer.json +++ b/composer.json @@ -16,8 +16,8 @@ } ], "require": { - "php": "^8.0", - "illuminate/contracts": "^9.0", + "php": "^8.1", + "illuminate/contracts": "^10.0", "spatie/laravel-package-tools": "^1.4.3" }, "require-dev": { diff --git a/src/Listeners/OtherDeviceLogoutListener.php b/src/Listeners/OtherDeviceLogoutListener.php index 5b49868..250a4ca 100644 --- a/src/Listeners/OtherDeviceLogoutListener.php +++ b/src/Listeners/OtherDeviceLogoutListener.php @@ -35,7 +35,7 @@ public function handle($event): void ]); } - foreach ($user->authentications()->whereLoginSuccessful(true)->get() as $log) { + foreach ($user->authentications()->whereLoginSuccessful(true)->whereNull('logout_at')->get() as $log) { if ($log->id !== $authenticationLog->id) { $log->update([ 'cleared_by_user' => true, diff --git a/src/Models/AuthenticationLog.php b/src/Models/AuthenticationLog.php index 898c865..0ef1f85 100755 --- a/src/Models/AuthenticationLog.php +++ b/src/Models/AuthenticationLog.php @@ -25,11 +25,8 @@ class AuthenticationLog extends Model 'cleared_by_user' => 'boolean', 'location' => 'array', 'login_successful' => 'boolean', - ]; - - protected $dates = [ - 'login_at', - 'logout_at', + 'login_at' => 'datetime', + 'logout_at' => 'datetime', ]; public function __construct(array $attributes = []) diff --git a/src/Traits/AuthenticationLoggable.php b/src/Traits/AuthenticationLoggable.php index 5b6e499..a7cb320 100644 --- a/src/Traits/AuthenticationLoggable.php +++ b/src/Traits/AuthenticationLoggable.php @@ -23,31 +23,31 @@ public function notifyAuthenticationLogVia(): array public function lastLoginAt() { - return optional($this->authentications()->first())->login_at; + return $this->authentications()->first()?->login_at; } public function lastSuccessfulLoginAt() { - return optional($this->authentications()->whereLoginSuccessful(true)->first())->login_at; + return $this->authentications()->whereLoginSuccessful(true)->first()?->login_at; } public function lastLoginIp() { - return optional($this->authentications()->first())->ip_address; + return $this->authentications()->first()?->ip_address; } public function lastSuccessfulLoginIp() { - return optional($this->authentications()->whereLoginSuccessful(true)->first())->ip_address; + return $this->authentications()->whereLoginSuccessful(true)->first()?->ip_address; } public function previousLoginAt() { - return optional($this->authentications()->skip(1)->first())->login_at; + return $this->authentications()->skip(1)->first()?->login_at; } public function previousLoginIp() { - return optional($this->authentications()->skip(1)->first())->ip_address; + return $this->authentications()->skip(1)->first()?->ip_address; } }