定制 aef/hypervel-permission 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

  1. Features
  2. Installation
  3. Configuration
  4. Basic Usage
  5. Advanced Usage
  6. Testing

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 aef/hypervel-permission 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 487
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-23