定制 nyoncode/laravel-permission-extended 二次开发

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

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

nyoncode/laravel-permission-extended

最新稳定版本:1.0.1

Composer 安装命令:

composer require nyoncode/laravel-permission-extended

包简介

Wildcard permission matching, super-admin gate, Blade directives and Livewire support built on spatie/laravel-permission.

README 文档

README

Tests Latest Version on Packagist Total Downloads License

Wildcard permissions, super-admin gate, auto middleware registration, Blade directives and Livewire support — all built on spatie/laravel-permission.

Support

Laravel 10 Laravel 11 Laravel 12 Laravel 13
PHP 8.2 -
PHP 8.3
PHP 8.4
PHP 8.5
// Wildcards just work in every Spatie method
$user->hasPermissionTo('admin.*');
$user->hasRoleOrPermission('editor|admin.*');

// Super-admin bypasses everything via Gate
@can('anything') YES @endcan

// Spatie middleware registered automatically
Route::middleware('permission:admin.*')

Installation

composer require nyoncode/laravel-permission-extended
php artisan permission-extended:install

The install command will publish config, Spatie migrations, run migrations and optionally add the trait to your User model.

Manual Setup

Change the HasRoles import on your User model — from Spatie to this package:

// Before:  use Spatie\Permission\Traits\HasRoles;
// After:
use NyonCode\PermissionExtended\Traits\HasRoles;

class User extends Authenticatable
{
    use HasRoles;
}

Do not use both Spatie's and this package's HasRoles on the same model — this one already includes Spatie's internally.

Features

Wildcard Permissions

$user->hasPermissionTo('admin.*');                   // any admin permission
$user->hasAnyPermission(['admin.*', 'posts.edit']);   // any match
$user->hasAllPermissions(['admin.*', 'posts.*']);     // all must match
$user->hasRoleOrPermission('editor|admin.*');         // role OR permission

@can('admin.*'), Gate::allows('admin.*') and middleware('permission:admin.*') all work transparently.

Super-Admin Role

Configured via config/permission-extended.php:

'super_admin_role' => 'super-admin', // or null to disable

Users with this role pass every Gate::allows() / @can() / $user->can() check automatically. No need to assign individual permissions.

Automatic Middleware Registration

Spatie's middleware is registered automatically — no manual setup in bootstrap/app.php:

// These just work out of the box:
Route::middleware('role:admin')
Route::middleware('permission:admin.*')
Route::middleware('role_or_permission:editor|admin.*')

Disable via 'register_middleware' => false in config.

Blade Directives

@canPermission('admin.*')              @endcanPermission
@canAnyPermission(['a.*', 'b.*'])      @endcanAnyPermission
@canAllPermissions(['a.*', 'b.*'])     @endcanAllPermissions
@hasRoleOrPermission('admin|a.*')      @endhasRoleOrPermission
@unlessCanPermission('admin.*')        @endunlessCanPermission

Native @can('admin.*') also works.

Livewire Integration

use NyonCode\PermissionExtended\Livewire\WithPermissions;

class AdminPanel extends Component
{
    use WithPermissions;

    public function mount()
    {
        $this->permAuthorize('admin.*');
    }
}
@if($this->permCan('posts.*'))
    <button wire:click="create">New</button>
@endif

Cache Management

php artisan permission:flush

Clears both Spatie's permission cache and the wildcard pattern cache.

Documentation

Testing

composer test

License

MIT

nyoncode/laravel-permission-extended 适用场景与选型建议

nyoncode/laravel-permission-extended 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 68 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「permission」 「roles」 「blade」 「wildcard」 「spatie」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 nyoncode/laravel-permission-extended 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 nyoncode/laravel-permission-extended 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-23