From 8e4ebb72e6d65404d6d998a32ce84bccbc553eb6 Mon Sep 17 00:00:00 2001 From: Jeff Idago <56063120+jidago@users.noreply.github.com> Date: Sat, 12 Nov 2022 15:39:10 +0800 Subject: [PATCH] fix: fix issue on log auth attempt --- src/Listeners/LogAuthenticationAttempt.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Listeners/LogAuthenticationAttempt.php b/src/Listeners/LogAuthenticationAttempt.php index 833b6a7..936229f 100644 --- a/src/Listeners/LogAuthenticationAttempt.php +++ b/src/Listeners/LogAuthenticationAttempt.php @@ -34,12 +34,21 @@ public function __construct(Request $request) */ public function handle(Attempting $event) { - $model = config('laralogs.user_model'); - $userColumn = config('laralogs.user_column'); - $userId = $model::where($userColumn, $event->credentials[$userColumn])->value('id'); + $user = config('laralogs.user_model', '\App\Models\User'); + $userColumn = config('laralogs.user_column', 'email'); + $userId = $user::where($userColumn, $event->credentials[$userColumn])->value('id'); - if ($userId) { - $model->logs()->save(app(Laralogs::class)->addLog('Attempting')); + if (! $userId) { + return; } + + $user = $user::find($userId); + + if (! $user) { + return; + } + + $laralogs = new Laralogs(); + $user->logs()->save($laralogs->addLog('Attempting')); } }