aef/hypervel-permission
Composer 安装命令:
composer require aef/hypervel-permission
包简介
Role & Permission management for Hypervel, with cache support
README 文档
README
Role & Permission management for the Hypervel Framework, with first-class cache support.
Effortlessly assign roles and permissions to your Hypervel users, speed-boosted by smart caching.
Table of Contents
Features
- 🔑 Create roles & permissions via models or artisan commands
- 🧑🤝🧑 Assign multiple roles to users (or vice versa)
- 🛂 Authorize via roles or direct permissions
- 🚀 Cache layer with configurable store, key & TTL
- 🛡 Multi-guard support out of the box
- 🔍 Clean, expressive API (
hasRole(),hasPermissionTo(), …) - 🧪 Thoroughly tested & production-ready
Installation
composer require aef/hypervel-permission
Configuration
Publish the config file and the migrations:
php artisan vendor:publish permission-config php artisan vendor:publish permission-migrations
In the providers array, add the following line:
'providers' => [ // Other service providers... Hypervel\Permission\PermissionServiceProvider::class, ],
Basic Usage
Creating permissions & roles
use Hypervel\Permission\Models\Permission; use Hypervel\Permission\Models\Role; Permission::create(['name' => 'edit articles']); Permission::create(['name' => 'delete articles']); $writer = Role::create(['name' => 'writer']); $writer->givePermissionTo('edit articles', 'delete articles'); $admin = Role::create(['name' => 'admin']); $admin->givePermissionTo(Permission::all());
Assigning and Revoking Roles/Permissions
$user = \App\Models\User::find(1); $user->assignRole('writer', 'admin'); $user->syncRoles(['writer', 'admin']); $user->removeRole('admin'); $user->givePermissionTo('publish articles'); $user->syncPermissions(['edit articles', 'delete articles']); $user->revokePermissionTo('edit articles'); // Remove single permission $user->revokePermissionTo('edit articles', 'delete articles'); // Remove multiple
Checking abilities
$user->hasPermissionTo('edit articles'); // true/false $user->hasRole('writer'); // true/false $user->hasAnyRole(['writer', 'moderator']); // true/false $user->hasAllPermissions(['edit', 'publish']); // true/false
Check if the current user has permission
Gate::allows('edit articles')
Getting all permissions
$user->getAllPermissions(); // direct + via roles $user->getPermissionsViaRoles(); // only via roles $user->permissions; // only direct
Advanced Usage
Caching is on by default and automatically flushed whenever a permission, role, or related pivot changes.
'cache' => [ 'store' => env('PERMISSION_CACHE_STORE', 'redis'), 'key' => env('PERMISSION_CACHE_KEY', 'hypervel.permission.cache'), 'expiration' => env('PERMISSION_CACHE_TTL', 3600), // seconds ],
Multiple guards
// creating Permission::create(['name' => 'edit articles', 'guard_name' => 'api']); Role::create(['name' => 'writer', 'guard_name' => 'api']); // checking (guard auto-detected from current auth) $user->hasPermissionTo('edit articles'); // defaults to current guard $user->hasPermissionTo('edit articles', 'api'); // explicit
aef/hypervel-permission 适用场景与选型建议
aef/hypervel-permission 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 487 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 04 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 aef/hypervel-permission 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 aef/hypervel-permission 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 487
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-23