rappasoft/laravel-authentication-log

SQL exception at logout

Crouxie opened this issue · 2 comments

Hi,

your package v1.x returns SQL error at logout:

Illuminate\Database\QueryException
SQLSTATE[42000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]A column has been specified more than once in the order by list. Columns in the order by list must be unique. (SQL: select top 1 * from [authentication_log] where [authentication_log].[authenticatable_type] = App\User and [authentication_log].[authenticatable_id] = 3 and [authentication_log].[authenticatable_id] is not null and [ip_address] = ::1 and [user_agent] = Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36 order by [login_at] desc, [login_at] desc)

which can be resolved by replacing:
$log = $user->authentications()->whereIpAddress($ip)->whereUserAgent($userAgent)->orderByDesc('login_at')->first();
with
$log = $user->authentications()->whereIpAddress($ip)->whereUserAgent($userAgent)->first();