Coder Social home page Coder Social logo

filament-auditing's Introduction

Filament Laravel Auditing

A Filament plugin for Laravel Auditing package. This plugin contains a relation manager for audits that you can add to your Filament resources.

This package provides a Filament resource manager that shows a table with all audits on view and edit pages and allows restore audits.

Installation

Note This plugin uses the Laravel Auditing package. First install and configure this package.

You can install the plugin via composer:

composer require tapp/filament-auditing:"^3.0"

Note For Filament 2.x check the 2.x branch

You can publish the view file with:

php artisan vendor:publish --tag="filament-auditing-views"

You can publish the translation files with:

php artisan vendor:publish --tag="filament-auditing-translations"

You can publish the config file with:

php artisan vendor:publish --tag="filament-auditing-config"

This is the content of the published config file:

<?php

return [

    'audits_sort' => [
        'column' => 'created_at',
        'direction' => 'desc',
    ],

    'is_lazy' => true,
    
    'audits_extend' => [
        // 'url' => [
        //     'class' => \Filament\Tables\Columns\TextColumn::class,
        //     'methods' => [
        //         'sortable',
        //         'searchable' => true,
        //         'default' => 'N/A'
        //     ]
        // ],
    ]

];

The audits_sort can be used to change the default sort on the audits table.

Usage

To show the audits table in your Filament resource, just add AuditsRelationManager::class on your resource's getRelations method:

use Tapp\FilamentAuditing\RelationManagers\AuditsRelationManager;

public static function getRelations(): array
{
    return [
        // ...
        AuditsRelationManager::class,
    ];
}

That's it, you're all set!

If you access your resource, and edit some data, you will now see the audits table on edit and view pages.

Extending Columns

In case you need to add a column to the AuditsRelationManager that does not already exist in the table, you can add it in the config using the format denoted in the example below, and it will be prepended to the table builder. The name of the column to be added is the key of an associative array that contains other information about the class, as shown in the example below. The class instance of the column must be added, but the methods can be left out if not required, or added wherever necessary.

<?php

return [

    'audits_extend' => [
       'url' => [
           'class' => \Filament\Tables\Columns\TextColumn::class, // required
           'methods' => [
               'sortable',
               'default' => 'NIL',
            ],
        ],
    ]

];

After adding this information in the config, please run this command for changes to take place.

php artisan optimize

As things stand, methods with two required parameters are not supported.

Permissions

Two permissions are registered by default, allowing access to:

  • audit: view audits
  • restoreAudit: restore audits

You can override these permissions by adding a policy with audit and restoreAudit.

Event emitted

The auditRestored event is emitted when an audit is restored, so you could register a listener using the $listeners property to execute some extra code after the audit is restored.

E.g.: on Edit page of your resource:

protected $listeners = [
    'auditRestored',
];

public function auditRestored()
{
    // your code
}

Event listener

The audits relation manager listen to the updateAuditsRelationManager event to refresh the audits table.

So you can dispatch this event in the Edit page of your resource (e.g.: in a edit page of a PostResource -> app/Filament/Resources/PostResource/Pages/EditPost.php) when the form is updated:

protected function afterSave(): void
{
    $this->dispatch('updateAuditsRelationManager');
}

Warning

When dispaching this event, set the is_lazy configuration to false, on filament-auditing.php config file, to avoid this exception: "Typed property Filament\Resources\RelationManagers\RelationManager::$table must not be accessed before initialization"

filament-auditing's People

Contributors

andreia avatar logicsatinn avatar husam-tariq avatar amendozaaguiar avatar haringsrob avatar joshembling avatar loanbesson avatar aseriousdeveloper avatar corean avatar nekoding 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.