A Filament plugin for Laravel Auditing package. This plugin contains a relation manager for audits that you can add to your Filament resources.
This package provides a Filament resource manager that shows a table with all audits on view and edit pages and allows restore audits.
Note This plugin uses the Laravel Auditing package. First install and configure this package.
You can install the plugin via composer:
composer require tapp/filament-auditing
You can publish the view file with:
php artisan vendor:publish --tag="filament-auditing-views"
You can publish the translation files with:
php artisan vendor:publish --tag="filament-auditing-translations"
You can publish the config file with:
php artisan vendor:publish --tag="filament-auditing-config"
This is the content of the published config file:
<?php
return [
'audits_sort' => [
'column' => 'created_at',
'direction' => 'desc',
],
'audits_extend' => [
// 'url' => [
// 'class' => \Filament\Tables\Columns\TextColumn::class,
// 'methods' => [
// 'sortable',
// 'searchable' => true,
// 'default' => 'N/A'
// ]
// ],
]
];
The audits_sort
can be used to change the default sort on the audits table.
To show the audits table in your Filament resource, just add AuditsRelationManager::class
on your
resource's getRelations
method:
use Tapp\FilamentAuditing\RelationManagers\AuditsRelationManager;
public static function getRelations(): array
{
return [
// ...
AuditsRelationManager::class,
];
}
That's it, you're all set!
If you access your resource, and edit some data, you will now see the audits table on edit and view pages.
In case you need to add a column to the AuditsRelationManager that does not already exist in the table, you can add it in the config using the format denoted in the example below, and it will be prepended to the table builder. The name of the column to be added is the key of an associative array that contains other information about the class, as shown in the example below. The class instance of the column must be added, but the methods can be left out if not required, or added wherever necessary.
<?php
return [
'audits_extend' => [
'url' => [
'class' => \Filament\Tables\Columns\TextColumn::class, // required
'methods' => [
'sortable',
'default' => 'NIL',
],
],
]
];
After adding this information in the config, please run this command for changes to take place.
php artisan optimize
As things stand, methods with two required parameters are not supported.
Two permissions are registered by default, allowing access to:
audit
: view auditsrestoreAudit
: restore audits
You can override these permissions by adding a policy with audit
and restoreAudit
.
The auditRestored
event is emitted when an audit is restored, so you could register a listener using the $listeners property to execute some extra code after the audit is restored.
E.g.: on Edit page of your resource:
protected $listeners = [
'auditRestored',
];
public function auditRestored()
{
// your code
}