fikrimastor / audit-login
Audit login is a another package for laravel framework. The purpose is to auditing login events
Fund package maintenance!
Fikri Mastor
Requires
- php: ^8.1
- illuminate/auth: ^10.0|^11.0
- illuminate/contracts: ^10.0|^11.0
- illuminate/database: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
This package is auto-updated.
Last update: 2025-05-01 00:14:57 UTC
README
Audit login is another package for Laravel framework. The purpose is auditing login events
Support us
Installation
You can install the package via composer:
composer require fikrimastor/audit-login
You can publish and run the migrations with:
php artisan vendor:publish --tag="audit-login-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="audit-login-config"
This is the contents of the published config file:
return [ 'enabled' => env('AUDIT_LOGIN_ENABLED', true), 'drivers' => [ 'database' => [ 'table' => env('AUDIT_LOGIN_DATABASE_TABLE', 'audit-logins'), 'connection' => env('AUDIT_LOGIN_DATABASE_CONNECTION', 'mysql'), ], ], ... ];
Usage
If you want to custom some actions, for example, while user login, you want to send an email notification, you may create new service provider and defined it in config/app.php.
So, under the new service provider, under the boot method, you can do something like this:
use \FikriMastor\AuditLogin\Facades\AuditLogin; use \YourProjectNamespace\YourCustomLoginEventClass; public function boot(): void { AuditLogin::recordLoginUsing(YourCustomLoginEventClass::class); }
And then, you can create a new class for your custom login event action class, for example:
use \FikriMastor\AuditLogin\Contracts\LoginEventContract; class YourCustomLoginEventClass implements LoginEventContract { public function handle(object $event, AuditLoginAttribute $attributes): void { AuditLogin::auditEvent($event, $attributes); // Do something here // Send email notification } }
The event object consists of the user object logged in, and the attribute object is the object that contains the login event attributes.
Some of it use Authenticatable contract, so you can use it to get the user data.
You may learn about Auth events in Laravel here.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.