A Filament plugin and a wrapper around Laravel Versionable to create versions Laravel Models. When ever you save a model, it would store the specified $versionable
fields to the Database and then you can revert to any target model state any time.
You can install the package via composer:
composer require mansoor/filament-versionable
Add Overtrue\LaravelVersionable\Versionable
trait to your model and set $versionable
attributes.
NOTE: Make sure to add protected $versionStrategy = VersionStrategy::SNAPSHOT; This would save all the $versionable attributes when any of them changed. There are different bug reports on using VersionStrategy::DIFF
use Overtrue\LaravelVersionable\VersionStrategy;
class Post extends Model
{
use Overtrue\LaravelVersionable\Versionable;
protected $versionable = ['title', 'content'];
protected $versionStrategy = VersionStrategy::SNAPSHOT;
}
Create a Revisons Resource Page to Show Revisions, it should extend the Mansoor\FilamentVersionable\RevisionsPage
. The page should look like:
namespace App\Filament\Resources\ArticleResource\Pages;
use App\Filament\Resources\ArticleResource;
use Mansoor\FilamentVersionable\RevisionsPage;
class ArticleRevisions extends RevisionsPage
{
protected static string $resource = ArticleResource::class;
}
Next, Add the Revisions page to your Resource
use App\Filament\Resources\ArticleResource\Pages;
public static function getPages(): array
{
return [
...
'revisions' => Pages\ArticleRevisions::route('/{record}/revisions'),
];
}
Add RevisionsAction
to your page, this action would appear when there are any versions for the model your are viewing/editing.
use Mansoor\FilamentVersionable\Page\RevisionsAction;
protected function getActions(): array
{
return [
RevisionsAction::make(),
];
}
You can also show the RevisionsAction
on your table rows.
use Mansoor\FilamentVersionable\Table\RevisionsAction;
$table->filters([
RevisionsAction::make(),
]);
You are all set! Your app should store the model states and you can manage them using Filament.
If you want to change the UI for Revisions page, you may publish the publish the views to do so.
php artisan vendor:publish --tag="filament-versionable-views"
If you want more control over how the versions are stored, you may read the Laravel Versionable Docs.
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.