Code Monkey home page Code Monkey logo

filament-versionable's Introduction

Filament Versionable

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.

Installation

You can install the package via composer:

composer require mansoor/filament-versionable

Usage

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.

Customisation

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.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

filament-versionable's People

Contributors

camillescholtz avatar loanbesson avatar mansoorkhan96 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.