Efforlessly manage your Eloquent model revisions in Filament. It includes:
You can install the package via composer:
composer require mansoor/filament-versionable
Then, publish the config file and migrations:
php artisan vendor:publish --provider="Overtrue\LaravelVersionable\ServiceProvider"
Finally, run the migration:
php artisan migrate
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
. If you were to create a Revisions page for ArticleResource
, it would 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 ArticleRevisions page (that you just created) 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 edit/view pages, this action would only appear when there are any versions for the model you are viewing/editing.
use Mansoor\FilamentVersionable\Page\RevisionsAction;Â protected function getHeaderActions(): array{ return [ RevisionsAction::make(), ];}
You can also add the RevisionsAction
to your table.
use Mansoor\FilamentVersionable\Table\RevisionsAction;Â $table->actions([ RevisionsAction::make(),]);
You are all set! Your app should store the model states and you can manage them in 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.
You can easily remove/strip HTML tags from the diff by just overriding shouldStripTags
method inside your revisions page.
class ArticleRevisions extends RevisionsPage{ protected static string $resource = ArticleResource::class;Â public function shouldStripTags(): bool { return true; }}
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.
Mansoor is a full-stack developer. He is currently working as a freelancer on Upwork.com, where he assists businesses in developing and maintaining their customer-facing and internal applications using Laravel, Vue.js, Tailwind CSS, and Livewire.