PHPackages                             huang-yi/laravel-rbac - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. huang-yi/laravel-rbac

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

huang-yi/laravel-rbac
=====================

A RBAC package for Laravel.

v2.0.0(5y ago)302217[2 issues](https://github.com/huang-yi/laravel-rbac/issues)MITPHP

Since Jun 17Pushed 5y ago2 watchersCompare

[ Source](https://github.com/huang-yi/laravel-rbac)[ Packagist](https://packagist.org/packages/huang-yi/laravel-rbac)[ RSS](/packages/huang-yi-laravel-rbac/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

English | [中文](README-cn.md)

Laravel RBAC
============

[](#laravel-rbac)

This package helps you to manage permissions and roles.

Installation
------------

[](#installation)

You may install this package via Composer:

```
composer require huang-yi/laravel-rbac
```

Next, you should publish configuration and migration files using the `vendor:publish` Artisan command:

```
php artisan vendor:publish --provider="HuangYi\Rbac\RbacServiceProvider"
```

Finally, you should run your database migrations:

```
php artisan migrate
```

Configuration
-------------

[](#configuration)

- **user**: The user model class you are using.
- **database**:
    - **connection**: The database connection for RBAC tables.
    - **prefix**: The common prefix for RBAC tables.
- **cache**: The cache switch.

Usage
-----

[](#usage)

Your User model must be configured to `rbac.user` option. It should implement the `HuangYi\Rbac\Contracts\Authorizable` interface and use the `HuangYi\Rbac\Concerns\Authorizable` trait.

```
namespace App;

use HuangYi\Rbac\Concerns\Authorizable;
use HuangYi\Rbac\Contracts\Authorizable as AuthorizableContract;

class User extends Authenticatable implement AuthorizableContract
{
    use Authorizable, Notifiable;
}
```

Store a permission to database:

```
use HuangYi\Rbac\Permission;

Permission::make('edit post');
```

Store a role to database:

```
use HuangYi\Rbac\Role;

Permission::make('personnel manager');
```

Attach or detach permissions to role:

```
$role->attachPermissions($permissions);

$role->detachPermissions($permissions);

$role->syncPermissions($permissions);
```

Attach or detach roles to user:

```
$user->attachRoles($roles);

$user->detachRoles($roles);

$user->syncRoles($roles);
```

Attach or detach permissions to user:

```
$user->attachPermissions($permissions);

$user->detachPermissions($permissions);

$user->syncPermissions($permissions);
```

Determine if the user has roles:

```
$user->hasRole('author');

$user->hasRoles(['author', 'personnel manager']);

$user->hasAnyRoles(['author', 'personnel manager']);
```

Determine if the user has permissions:

```
$user->hasPermission('create post');

$user->hasPermissions(['create post', 'edit post']);

$user->hasAnyPermissions(['create post', 'edit post']);

// this is similar to hasAnyPermissions
$user->can('edit post|edit post');
```

Super Admin
-----------

[](#super-admin)

You may register a callback for determining if the user is a super admin by using `Rbac::checkSuperAdminUsing()` method:

```
namespace App\Providers;

use HuangYi\Rbac\Rbac;
use Illuminate\Support\ServiceProvider;

class AuthServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Rbac::checkSuperAdminUsing(function ($user) {
            return in_array($user->email, ['admin@example.com']);
        });
    }
}
```

Middleware
----------

[](#middleware)

```
// role middleware
Route::get('admin/staffs', [StaffController::class, 'index'])->middleware('role:personnel manager|vice president');

// permission middleware
Route::post('post/{post}', [PostController::class, 'update'])->middleware('permission:create post|edit post');

// this is similar to 'permission' middleware
Route::post('post/{post}', [PostController::class, 'update'])->middleware('can:create post|edit post');
```

Blade Directives
----------------

[](#blade-directives)

Role directives:

- `@role`, `@elserole`, `@endrole` → `hasRole`
- `@roles`, `@elseroles`, `@endroles` → `hasRoles`
- `@anyroles`, `@elseanyroles`, `@endanyroles` → `hasAnyRoles`

Permission directives:

- `@permission`, `@elsepermission`, `@endpermission` → `hasPermission`
- `@permissions`, `@elsepermissions`, `@endpermissions` → `hasPermissions`
- `@anypermissions`, `@elseanypermissions`, `@endanypermissions` → `hasAnyPermissions`

Tests
-----

[](#tests)

```
composer test
```

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2155d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c073c577396659588206b31e05f0a8357b091506ec4c3569a97d67cb49dd10f2?d=identicon)[huangyi](/maintainers/huangyi)

---

Top Contributors

[![huang-yi](https://avatars.githubusercontent.com/u/6905173?v=4)](https://github.com/huang-yi "huang-yi (43 commits)")

---

Tags

laravellaravel-rbacpermissionrbaclaravelpermissionrbac

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/huang-yi-laravel-rbac/health.svg)

```
[![Health](https://phpackages.com/badges/huang-yi-laravel-rbac/health.svg)](https://phpackages.com/packages/huang-yi-laravel-rbac)
```

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k89.8M1.0k](/packages/spatie-laravel-permission)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[casbin/laravel-authz

An authorization library that supports access control models like ACL, RBAC, ABAC in Laravel.

324339.9k4](/packages/casbin-laravel-authz)[hosseinhezami/laravel-permission-manager

Advanced permission manager for Laravel.

403.3k](/packages/hosseinhezami-laravel-permission-manager)[wnikk/laravel-access-rules

Simple system of ACR (access control rules) for Laravel, with roles, groups, unlimited inheritance and possibility of multiplayer use.

103.6k1](/packages/wnikk-laravel-access-rules)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
