Filament plugin for archiving and unarchiving table records (eloquent models) based on the Laravel Archivable package by Joe Butcher.
This filament plugin adds an ArchiveAction, an UnArchiveAction and a ArchivedFilter to your resource tables. It's also possible to add custom row-classes for archived records. In addition to table-actions, the package provides also page-actions for view/edit pages to archive and unarchive your records.
- PHP ^8.3
- Laravel ^11.0
- Filament ^3.0
- Laravel Archivable ^1.4 (installed with this plugin)
You can install the package via composer:
composer require okeonline/filament-archivable
Then, add the plugin to the AppPanelProvider
:
class AppPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugin(\Okeonline\FilamentArchivable\FilamentArchivablePlugin::make());
}
}
This filament plugin automatically installs the Laravel Archivable package by Joe Butcher.
Follow his installation instructions, which -in short- instructs:
- Add a
archived_at
column to your table - Use the
Archivable
-trait on your model
As soon as the Archivable
-trait from the Laravel Archivable package is added to the model, it is possible to add the following actions to the corresponding resource table:
use Okeonline\FilamentArchivable\Tables\Actions\ArchiveAction;
use Okeonline\FilamentArchivable\Tables\Actions\UnArchiveAction;
// ...
class UserResource extends Resource
{
// ...
public static function table(Table $table): Table
{
return $table
// ...
->actions([
ArchiveAction::make(),
UnArchiveAction::make(),
]);
}
}
It will show the ArchiveAction
on records that aren't archived, and will show the UnArchiveAction
on those which are currently archived:
You should add both actions to the same table. The action itself wil determine if it should be shown on the record.
The actions are normal table actions, similar to the Delete and Restore table actions of FilamentPHP. You can add all features that are described in the FilamentPHP Table Actions Documentation, like:
hiddenLabel()
tooltip()
disabled()
icon()
- ... etc.
ArchiveAction::make()
->hiddenLabel()
->tooltip('Archive'),
The table actions call the $model->archive()
and $model->unArchive()
methods that are provided by the Laravel Achivable package.
As soon as the Archivable
-trait from the Laravel Archivable package is added to the model, it is possible to add the following actions to the resource pages:
// in e.g. Filament/PostResource/EditPage.php
use Okeonline\FilamentArchivable\Actions\ArchiveAction;
use Okeonline\FilamentArchivable\Actions\UnArchiveAction;
// ...
protected function getHeaderActions(): array
{
return [
ArchiveAction::make(),
UnArchiveAction::make(),
];
}
It will show the ArchiveAction
on records that aren't archived, and will show the UnArchiveAction
on those which are currently archived:
Be aware that there is a difference between table actions and normal (page) actions. You can not use the page actions as a table action, vice versa. Nevertheless, the business-logic is the same. Read this page for more information about the difference.
You should add both actions to the same page. The action itself wil determine if it should be shown on the record. Check this if you want to edit (and unarchive) records that are being archived.
The actions are normal actions, similar to the Delete and Restore actions of FilamentPHP. You can add all features that are described in the FilamentPHP Actions Documentation, like:
color()
size()
disabled()
icon()
- ... etc.
use Filament\Support\Enums\ActionSize;
ArchiveAction::make()
->color('success')
->size(ActionSize::Large),
It is also possible to add a ArchivedFilter
to the resoucre table, which adds three filtering options:
- Show only unarchived records
- Show only archived records
- Show both
By default, an unfiltered table will only show the unarchived records, as the Laravel Archivable package comes with a default global scope to query records with
archived_at IS NULL
You can add the filter by adding ArchivedFilter
to your array of resource table filters:
use Okeonline\FilamentArchivable\Tables\Filters\ArchivedFilter;
public static function table(Table $table): Table
{
return $table
// ...
->filters([
ArchivedFilter::make(),
]);
}
The ArchivedFilter
will respect all options that Tenary Filters have, so check the Tenary Filter Documentation of Filament to customize the filter.
If you want to be able to view/edit/delete archived records, you should disable the global ArchivedScope::class
on your resource getEloquentQuery()
method:
// in your resource:
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use LaravelArchivable\Scopes\ArchivableScope;
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->withoutGlobalScopes([
SoftDeletingScope::class, // only if soft deleting is also active, otherwise it can be ommitted
ArchivableScope::class,
]);
}
See Disabeling global scopes on Filament for more information about the default resource query.
This plugin comes with a Table::macro
which allows you to add custom (CSS/Tailwind) classes to table-rows that are archived:
Just add the method ->archivedRecordClasses()
to your table with archived results.
public static function table(Table $table): Table
{
return $table
->archivedRecordClasses(['opacity-25']);
}
- en - English
- nl - Dutch
You can publish and change the language files by running:
php artisan vendor:publish --tag=filament-archivable-translations
Minimal dev-requirement:
- filament/tables ^3.2.57
composer test
Please see CHANGELOG for more information on what has changed recently.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.