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.
Version | Doc. |
---|---|
V1 | Read Doc. |
V2 | Read Doc. |
- Installation
- Adding Role Select
- Multi Panel
- Defining Permissions
- Granting Access
- Additional Methods (optional)
- Custom Access
- Multi Tenancy
- Vendor Publish
- Meta Options
- Traits Class
- License
- Bug Reports or Issues
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
}
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')),
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
.
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'),
];
}
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');
}
When checking access outside an authenticated context (e.g., in queues or commands), use:
return hexa()->user(User::first())->can('user.index');
Filament supports visible
on components like Action
, Column
, Input
, etc.:
Actions\CreateAction::make('create')
->visible(fn() => hexa()->can(['user.index', 'user.create']));
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');
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'),
];
}
public $hexaSort = 4;
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([...]);
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.
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 |
We're working on the official license page β and it's coming soon. Something exciting is on the way, so stay tuned right here.
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! π§βπ»