tiagolemosneitzke/filamentacl

A flexible and lightweight Access Control List (ACL) plugin for managing user permissions and roles in Laravel applications

v1.1.0 2025-01-07 18:49 UTC

README

A flexible and lightweight Access Control List (ACL) plugin for managing user permissions and roles in Laravel applications using Filament.

Attention

This package doesn't work with Tenancy.

Latest Version on Packagist Total Downloads Packagist License

You can install the package via composer:

composer require tiagolemosneitzke/filamentacl -W

This will install the Filament ACL package along with its dependencies, including spatie/laravel-permission.

After the installation, publish the migration and configuration files:

php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider"

Run the migrations to create the necessary tables:

php artisan migrate

Add the HasRoles trait to your User model:

use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable
{
    use HasRoles;
}

Register the plugin in your Panel provider:

use TiagoLemosNeitzke\FilamentAcl\FilamentAclPlugin;
 
public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
             FilamentAclPlugin::make()
        ]);
}

You can then install the Filament ACL package with the following command:

php artisan filament-acl:install

This will publish the config file.

Alternatively, you can publish only the config file with:

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

This is the contents of the published config file:

return [
    'permission' => [
        'prefixes' => [
            'view',
            'view_any',
            'create',
            'update',
            'restore',
            'delete',
            'force_delete'
        ]
    ],

    'roles_prefixes' => [
        'admin',
    ]
];

Also, you can publish manually all the files with:

php artisan vendor:publish --provider="TiagoLemosNeitzke\FilamentAcl\FilamentAclServiceProvider"

Or you can publish the necessary files one by one

php artisan vendor:publish --tag=filament-acl-config
php artisan vendor:publish --tag=filament-acl-stubs

You don't need to publish all the files for the package work, but you need to publish the settings file and configuring correctly the Laravel Permissions Package.

In your UserResource file, you should add the below code to edit and view the permission of the user:

use TiagoLemosNeitzke\FilamentAcl\Models\Role;

public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Forms\Components\Select::make('roles')
                    ->label('Role')
                    ->relationship('roles', 'name')
                    ->options(Role::all()->pluck('name', 'id'))
                    ->multiple()
                    ->preload()
                    ->searchable(),
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('roles.name')
                    ->label('Is Admin?')
                    ->badge(),
             ]);
    }

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.