label84 / laravel-auth-log
Log user authentication actions in Laravel.
Installs: 31 974
Dependents: 0
Suggesters: 0
Security: 0
Stars: 36
Watchers: 1
Forks: 5
Open Issues: 0
Requires
- php: ^8.0
- illuminate/auth: ^10.0|^11.0
- illuminate/database: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
Requires (Dev)
- larastan/larastan: ^2.0
- laravel/pint: ^1.14
- orchestra/testbench: ^8.0|^9.0
README
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.
Laravel Support
Installation
1. Install the package via composer
composer require label84/laravel-auth-log
2. Publish the config file and migration
php artisan vendor:publish --provider="Label84\AuthLog\AuthLogServiceProvider" --tag="config" php artisan vendor:publish --provider="Label84\AuthLog\AuthLogServiceProvider" --tag="migrations"
3. Run migration
php artisan migrate
Usage
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.
Enable/disable logging
You can add the AUTH_LOG_ENABLED=
to your .env
file to enable/disable the logging.
// .env AUTH_LOG_ENABLED=true
Table format example
Tests
./vendor/bin/phpstan analyse ./vendor/bin/phpunit