nyoncode/laravel-permission-extended 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱: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

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固