Code Monkey home page Code Monkey logo

filament-archivable's Introduction

Filament Archivable

Filament plugin to archive, unarchive and filter records

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

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.

Requirements

  • PHP ^8.3
  • Laravel ^11.0
  • Filament ^3.0
  • Laravel Archivable ^1.4 (installed with this plugin)

Installation

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:

  1. Add a archived_at column to your table
  2. Use the Archivable-trait on your model

Usage

Archive and Unarchive actions

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:

Actions

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 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 actions call the $model->archive() and $model->unArchive() methods that are provided by the Laravel Achivable package.

Filtering

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(),
        ]);
}

Filters

The ArchivedFilter will respect all options that Tenary Filters have, so check the Tenary Filter Documentation of Filament to customize the filter.

Add custom classes to archived rows

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']);
}

Custom classes

Supported languages

  • en - English
  • nl - Dutch

You can publish and change the language files by running:

php artisan vendor:publish --tag=filament-archivable-translations

Testing

Minimal dev-requirement:

  • filament/tables ^3.2.57
composer test

Changelog

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

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-archivable's People

Contributors

rvzug 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.