8000 GitHub - hexters/hexa-docs: Effortless role and permission management plugin for Filament
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Effortless role and permission management plugin for Filament

License

Notifications You must be signed in to change notification settings

hexters/hexa-docs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

32 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Filament Hexa V2 (Coming Soon)

Filament Hexa is an easy-to-use role and permission management plugin for Filament. Now in version 2, it supports multi-panel setups, is easier to use, and customizable.

Banner

Versions

Version Doc.
V1 Read Doc.
V2 Read Doc.

Index

Installation

Then install the package:

composer require hexters/hexa

Then run the migration for roles:

php artisan migrate

After installation, register the plugin in your panel:

use Filament\Panel;
use Hexters\Hexa\Hexa;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            Hexa::make(),
        ]);
}

Then register the access trait in the User model:

use Hexters\Hexa\HexaRolePermission;

class User extends Authenticatable
{
    use HasFactory, Notifiable;
    use HexaRolePermission; // Add this trait
}

Adding Role Select

To assign a role to a user, add a select input in your UserResource form:

Forms\Components\Select::make('roles')
    ->label(__('Role Name'))
    ->relationship('roles', 'name')
    ->placeholder(__('Superuser')),

Multi Panel

Filament Hexa supports multiple panels as long as each panel uses a different Auth Guard. The default guard is web.

public function panel(Panel $panel): Panel
{
    return $panel
        ->authGuard('reseller');
}

public function panel(Panel $panel): Panel
{
    return $panel
        ->authGuard('customer');
}

Configure guards in config/auth.php.

Defining Permissions

Permissions can be declared in Pages, Resources, Widgets, and Clusters. Example:

public function defineGates(): array
{
    return [
        'user.index' => __('Allows to view list of users'),
        'user.create' => __('Allows to create new user'),
        'user.update' => __('Allows to update user'),
        'user.delete' => __('Allows to delete user'),
    ];
}

Granting Access

If a user has no assigned role, they are treated as a Superuser, meaning they can access all defined permissions.

public static function canAccess(): bool
{
    return hexa()->can('user.index');
}

Check for User

When checking access outside an authenticated context (e.g., in queues or commands), use:

return hexa()->user(User::first())->can('user.index');

Visible Access

Filament supports visible on components like Action, Column, Input, etc.:

Actions\CreateAction::make('create')
    ->visible(fn() => hexa()->can(['user.index', 'user.create']));

Laravel Access

Laravel's native authorization features:

Auth::user()->can('user.create');
Gate::allows('user.create');

// Only works in authenticated context (e.g., requests)
Gate::forUser(User::first())->allows('user.create');

@can('user.create')
    ...
@endcan

βœ… For non-authenticated contexts:

hexa()->user(User::first())->can('user.create');

Additional Methods (optional)

Adding Descriptions to Roles and Gates

public function roleDescription(): ?string
{
    return __('Controls access to create, read, update, delete, and more.');
}

public function defineGateDescriptions(): array
{
    return [
        'user.index' => __('Admins can access the User page'),
        'user.create' => __('Admins can create new Users'),
    ];
}

Setting Role Display Order

public $hexaSort = 4;

Custom Access

You can define additional gates using GateItem:

Hexa::make()
    ->gateItems([
        GateItem::make(__('Horizon'))
            ->description(__('Allows user to manage horizon page'))
            ->gateItems([
                'horizon.page' => __('Horizon Page')
            ])
            ->gateItemDescriptions([
                'other.index' => __('Allow user to access horizon page')
            ]),
    ]);

To customize the menu:

Hexa::make()
    ->shouldRegisterNavigation(true)
    ->navigationName(__('Role & Access'))
    ->navigationGroup('Settings')
    ->navigationIcon('heroicon-o-lock-open')
    ->gateItems([...]);

Multi Tenancy

Filament Hexa supports multi-tenancy. The HexaRole model includes a team_id field and team relationship. You can integrate it with Filament's multi-tenancy setup.

Vendor Publish

To override the role model (e.g., for customizing tenant relationships), publish the config:

php artisan vendor:publish --provider="Hexters\Hexa\HexaServiceProvider"

Meta Options

< 7693 /a>
hexa()->setOption('key-option', 'value-option');
hexa()->getOption('key-option', 'default');
hexa()->dateOption('key-option');
hexa()->getOptionKeys();
Name Description
HexaRolePermission Used on the Authenticatable model
HasHexaRole Used on Resources, Pages, Widgets, Clusters
UuidGenerator Used on models with a uuid field
UlidGenerator Used on models with a ulid field

License

We're working on the official license page β€” and it's coming soon. Something exciting is on the way, so stay tuned right here.

Bug Reports or Issues

Please report issues via GitHub: Filament Hexa Issue Tracker

Thank you for using Filament Hexa. We hope it helps accelerate your development process.

Happy Coding! πŸ§‘β€πŸ’»

0