View and manage Audit History for your Laravel Models in Filament. Built upon the Laravel Auditing package by OwenIT.
This package requires the latest major version of Laravel Auditing, v14.
It'll be installed automatically, but it's recommended to install Laravel Auditing in your own repository.
Make sure to follow the installation instructions. It's recommended to give the full documentation a read, too.
composer require owen-it/laravel-auditing
Namely, make sure you publish the migration and configuration:
php artisan vendor:publish --provider "OwenIt\Auditing\AuditingServiceProvider" --tag="config"
php artisan vendor:publish --provider "OwenIt\Auditing\AuditingServiceProvider" --tag="migrations"php artisan migrate
You can then install this package via composer:
composer require crescent-purchasing/filament-auditing
To use this plugin within your panel, add it to your plugins()
section in your PanelProvider
:
use CrescentPurchasing\FilamentAuditing\FilamentAuditingPlugin;use Filament\Panel;use Filament\PanelProvider; class AuditPanelProvider extends PanelProvider{ public function panel(Panel $panel): Panel { return $panel ->default() ->id('admin') // ... ->plugins([ FilamentAuditingPlugin::make(), ]); }}
This will automatically add the Resource Page to your Filament Panel. It should also provide some basic configuration that will work for most use-cases.
The plugin allows you to view the audit history of a specific record. To do so, simply add the Relation Manager to the resource:
use CrescentPurchasing\FilamentAuditing\Filament\RelationManagers\AuditsRelationManager; public static function getRelations(): array{ return [ AuditsRelationManager::class, ];}
The plugin comes with the OwnedAuditsRelationManager
. This by default doesn't have support with Laravel Auditing.
However, it's easy to add the support. Simply add a relation function like the following to each of your User Models:
use Illuminate\Database\Eloquent\Relations\MorphMany;use OwenIt\Auditing\Models\Audit; /** * @return MorphMany<Audit, $this> */public function ownedAudits(): MorphMany{ return $this->morphMany(Audit::class, 'user');}
Then, add the relation manager to your Resources as normal:
use CrescentPurchasing\FilamentAuditing\Filament\RelationManagers\OwnedAuditsRelationManager; public static function getRelations(): array{ return [ OwnedAuditsRelationManager::class, ];}
You can configure a few parts of the application.
Cursor Pagination for Audits is enabled by default. You can disable this using cursorPagination()
:
use CrescentPurchasing\FilamentAuditing\FilamentAuditingPlugin; FilamentAuditingPlugin::make() ->cursorPagination(false)
By default, the configured audit.implementation
config value is used for the Audit Model.
This can be modified using model()
use CrescentPurchasing\FilamentAuditing\FilamentAuditingPlugin; FilamentAuditingPlugin::make() ->model(\OwenIt\Auditing\Models\Audit::class)
The Auditable Type in tables is formatted as a Headline of the Class Basename.
You can customise this using a closure within formatAuditableTypeUsing()
:
use CrescentPurchasing\FilamentAuditing\FilamentAuditingPlugin; FilamentAuditingPlugin::make() ->formatAuditableTypeUsing(fn(string $value): string => strtoupper($value))
The event names are turned into a Headline. You can customise this using formatEventUsing()
:
use CrescentPurchasing\FilamentAuditing\FilamentAuditingPlugin; FilamentAuditingPlugin::make() ->formatEventUsing(fn(string $value): string => strtoupper($value))
No Navigation Group for the Resource is set by default. You can set this using navigationGroup()
:
use CrescentPurchasing\FilamentAuditing\FilamentAuditingPlugin; FilamentAuditingPlugin::make() ->navigationGroup('Administration')
The Resource icon by default is heroicon-o-clock
. You can set this using navigationIcon()
:
use CrescentPurchasing\FilamentAuditing\FilamentAuditingPlugin; FilamentAuditingPlugin::make() ->navigationIcon('heroicon-o-check')
The default list of User classes is determined using the audit.user.guards
config value.
This then checks the list of auth providers in auth.providers
.
You can change this behaviour with users()
:
use CrescentPurchasing\FilamentAuditing\FilamentAuditingPlugin; FilamentAuditingPlugin::make() ->users([\CrescentPurchasing\FilamentAuditing\Tests\Models\User::class])
By default, viewing user information of an Audit only displays 2 columns: email
and id
.
You can specify additional columns with userSchema
:
use CrescentPurchasing\FilamentAuditing\FilamentAuditingPlugin;use Filament\Forms\Components\TextInput; FilamentAuditingPlugin::make() ->userSchema([ TextInput::make('first_name'), TextInput::make('last_name'), ])
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.
Crescent Purchasing Consortium provide purchasing frameworks, dynamic purchasing systems (DPS) and procurement consultancy services for schools, academies, colleges, universities and other educational organisations.