fikrimastor/audit-login

Audit login is a another package for laravel framework. The purpose is to auditing login events

v1.1.1 2024-12-24 19:07 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.