tapp/filament-authentication-log

Filament authentication log plugin.

v3.1.1 2024-06-25 20:50 UTC

This package is auto-updated.

Last update: 2024-12-25 21:51:15 UTC


README

Latest Version on Packagist Code Style Action Status - Pint Total Downloads

A Filament plugin for Laravel Authentication Log package.

This package provides a Filament resource and a relation manager for Laravel Authentication Log.

Requirements

Dependencies

Version Compatibility

Installation

You can install the plugin via Composer:

composer require tapp/filament-authentication-log:"^3.1"

Follow the configuration instruction for laravel-authentication-log

  • Publish and run the migrations
  • Add the AuthenticationLoggable and Notifiable traits to your User model

Note For Filament 2.x check the 2.x branch

You can publish the translations files with:

php artisan vendor:publish --tag="filament-authentication-log-translations"

You can publish the config file with:

php artisan vendor:publish --tag="filament-authentication-log-config"

Using the Resource

Add this plugin to a panel in the plugins() method. E.g., in app/Providers/Filament/AdminPanelProvider.php:

use Tapp\FilamentAuthenticationLog\FilamentAuthenticationLogPlugin;
 
public function panel(Panel $panel): Panel
{
    return $panel
        // ...
        ->plugins([
            FilamentAuthenticationLogPlugin::make()
                // ->panelName('admin') // Optional: specify the panel name if needed
        ]);
}

That's it! Now you can see the Authentication Log resource on left sidebar.

This customization ->panelName('admin') allows for better organization if you have multiple panels, such as Developer and Admin panels, where the FilamentAuthenticationLogPlugin is used in one panel but the user resource is available only in another panel.

Resource appearance

Filament Authentication Log Resource

Filament Authentication Log Resource with filters and tooltip

Using the Relation Manager

Add the Tapp\FilamentAuthenticationLog\RelationManagers\ to the getRelations() method on the Filament resource where the model uses the AuthenticationLoggable trait.

E.g. in App\Filament\Resources\UserResource.php:

use Tapp\FilamentAuthenticationLog\RelationManagers\AuthenticationLogsRelationManager;
 
public static function getRelations(): array
{
    return [
        AuthenticationLogsRelationManager::class,
        // ...
    ];
}

Relation manager appearance

Filament Authentication Log Relation Manager

Displaying Authenticatable Names

To display the actual name of the authenticatable user instead of the class name, you can configure the plugin to show a specific field. By default, it will use the name field if available. If your model does not have a name column, you can add a custom attribute:

In your model:

public function getNameAttribute(): string
{
    return trim($this->first_name . ' ' . $this->last_name);
}

Configuration

To specify a custom field to display for the authenticatable user, update the config/filament-authentication-log.php configuration file:

'authenticatable' => [
    'field-to-display' => 'name', // Change 'name' to your custom field if needed
],