The laravel-auth-log
package will log all the default Laravel authentication events (Login, Attempting, Lockout, etc.) to your database. In the config file you can select the events that you would like to log. It will save the event name, email, user id, ip address and user agent to the database. No other configurations are required. This package could be useful for tracking unwanted activity in your Laravel application.
Version | Release |
---|---|
11.x | ^1.3 |
10.x | ^1.2 |
composer require label84/laravel-auth-log
php artisan vendor:publish --provider="Label84\AuthLog\AuthLogServiceProvider" --tag="config"
php artisan vendor:publish --provider="Label84\AuthLog\AuthLogServiceProvider" --tag="migrations"
php artisan migrate
In the config file config/authlog.php
you can (un)comment the events that you'd like to log to your database.
// config/authlog.php
return [
// ...
'events' => [
\Illuminate\Auth\Events\Registered::class,
\Illuminate\Auth\Events\Attempting::class,
// \Illuminate\Auth\Events\Authenticated::class,
\Illuminate\Auth\Events\Login::class,
\Illuminate\Auth\Events\Failed::class,
// \Illuminate\Auth\Events\Validated::class,
\Illuminate\Auth\Events\Verified::class,
// \Illuminate\Auth\Events\Logout::class,
// \Illuminate\Auth\Events\CurrentDeviceLogout::class,
// \Illuminate\Auth\Events\OtherDeviceLogout::class,
\Illuminate\Auth\Events\Lockout::class,
\Illuminate\Auth\Events\PasswordReset::class,
],
];
In the same file you can can also change the database connection and table name.
You can add the AUTH_LOG_ENABLED=
to your .env
file to enable/disable the logging.
// .env
AUTH_LOG_ENABLED=true
id | event_name | user_id | ip_address | user_agent | context | created_at | |
---|---|---|---|---|---|---|---|
1 | Attempting | [email protected] | 127.0.0.1 | Mozilla/5.0 (Windows NT 10.0... | 2022-01-10 00:00:00 | ||
2 | Login | 1 | 127.0.0.1 | Mozilla/5.0 (Windows NT 10.0... | 2022-01-10 00:00:00 |
./vendor/bin/phpstan analyse
./vendor/bin/phpunit