hexters/hexa-lite
Composer 安装命令:
composer require hexters/hexa-lite
包简介
Filament Hexa Lite is a effortless role and permission management plugin for Filament
关键字:
README 文档
README
Filament Hexa Lite is a free and developer-friendly role and permission management plugin for FilamentPHP V5.
It helps you manage user roles and access permissions across Resources, Pages, and Widgets — with support for multi-panel apps via custom guards.
Currently in version 3, Hexa Lite is more intuitive, customizable, and production-ready.
📖 Full documentation: hexters.github.io/hexa-docs
Version Docs.
| Version | Filament | Doc. |
|---|---|---|
| V1 | V3 | Read Doc. |
| V2 | V3 | Read Doc. |
| V3 | V5 | Read Doc. |
Index
- Installation
- Adding Role Selection
- Multi Panel Support
- Defining Permissions
- Access Control
- Available Traits
- Features in Pro Version
- License
- Issues & Feedback
Installation
Install the package via Composer:
composer require hexters/hexa-lite
Run the database migration:
php artisan migrate
Register the plugin in your Filament panel:
use Filament\Panel; use Hexters\HexaLite\HexaLite; public function panel(Panel $panel): Panel { return $panel ->plugins([ HexaLite::make(), ]); }
Apply the trait to your User model:
use Hexters\HexaLite\HexaLiteRolePermission; class User extends Authenticatable { use HasFactory, Notifiable; use HexaLiteRolePermission; }
Adding Role Selection
To allow role assignment via the admin panel, add a select input to your UserForm class:
use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; public static function form(Form $form): Form { return $form ->schema([ TextInput::make('email') ->unique(ignoreRecord: true) ->required(), Select::make('roles') ->label(__('Role Name')) ->relationship('roles', 'name') ->placeholder(__('Superuser')), ]); }
Multi Panel Support
Hexa Lite supports multiple panels, each with its own auth guard.
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
Define permissions using the defineGates() method on Resources, Pages, or Widgets:
use Hexters\HexaLite\HasHexaLite; class UserResource extends Resource { use HasHexaLite; public function defineGates(): array { return [ 'user.index' => __('Allows viewing the user list'), 'user.create' => __('Allows creating a new user'), 'user.update' => __('Allows updating users'), 'user.delete' => __('Allows deleting users'), ]; } }
Access Control
Users with no assigned role are treated as Superusers and have full access by default.
To restrict access to a resource:
use Illuminate\Auth\Access\Response; use Illuminate\Database\Eloquent\Model; public static function getViewAnyAuthorizationResponse(): Response { return hexa()->can('user.index') ? Response::allow() : Response::deny(); } public static function getCreateAuthorizationResponse(): Response { return hexa()->can('user.create') ? Response::allow() : Response::deny(__('You do not have permission to create user.')); } public static function getEditAuthorizationResponse(Model $record): Response { return hexa()->can('user.update') ? Response::allow() : Response::deny(__('You do not have permission to edit this.')); } public static function getDeleteAuthorizationResponse(Model $record): Response { return hexa()->can('user.delete') ? Response::allow() : Response::deny(__('You do not have permission to delete user.')); } public static function getDeleteAnyAuthorizationResponse(): Response { return hexa()->can('user.delete') ? Response::allow() : Response::deny(__('You do not have permission to delete users.')); }
Check Permissions in Code
Useful in queued jobs, commands, or background services:
return hexa()->user(User::first())->can('user.index');
Visible Access
Use visible() to conditionally display UI elements:
Actions\CreateAction::make('create') ->visible(fn() => hexa()->can(['user.index', 'user.create']));
Laravel Integration
You can still use Laravel’s native authorization:
Auth::user()->can('user.create'); Gate::allows('user.create'); Gate::forUser(User::first())->allows('user.create'); @can('user.create') // Blade directive @endcan
Available Traits
| Trait | Description |
|---|---|
HexaLiteRolePermission |
Apply to your Authenticatable user model |
HasHexaLite |
Use in Resources, Pages, Widgets, or Clusters |
UuidGenerator |
Use on models with uuid fields |
UlidGenerator |
Use on models with ulid fields |
Features in Pro Version
Need more flexibility and control?
Filament Hexa Pro v3 unlocks powerful features designed for serious projects:
- Role & permission descriptions
- Custom role sorting
- Gate grouping (with nested access)
- Multi-tenancy support
- Meta option storage
A small investment for a much more capable permission system.
Learn more in the official documentation:
👉 Hexa Pro Documentation
License
This project is open-source and licensed under the MIT License. You are free to use, modify, and distribute it with attribution.
Issues & Feedback
Found a bug or want to contribute?
Open an issue at: https://github.com/hexters/hexa-lite/issues
Thank you for using Filament Hexa Lite!
hexters/hexa-lite 适用场景与选型建议
hexters/hexa-lite 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.39k 次下载、GitHub Stars 达 93, 最近一次更新时间为 2024 年 07 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Hexa plugin」 「role and permission Filament」 「role management Filament」 「access permissions Filament」 「Hexa Filament」 「hexters ladmin」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hexters/hexa-lite 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hexters/hexa-lite 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hexters/hexa-lite 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP library for color manipulation and conversion.
CakePHP 4.x AdminLTE Theme.
Provide a way to secure accesses to all routes of an symfony application.
PHP library to generate random strings
The library provides a flexible way to add role-based access control management to CakePHP 3.x
A Laravel Nova tool for `ACL` based on `laratrust` package.
统计信息
- 总下载量: 11.39k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 93
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-01
