PHPackages                             binary-cats/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. binary-cats/laravel-rbac

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

binary-cats/laravel-rbac
========================

Laravel enum-backed RBAC extension of spatie/laravel-permission

2.1.0(3mo ago)7838.1k↓63.1%2[2 issues](https://github.com/binary-cats/laravel-rbac/issues)[2 PRs](https://github.com/binary-cats/laravel-rbac/pulls)MITPHPPHP ^8.4CI passing

Since Mar 19Pushed 1w ago2 watchersCompare

[ Source](https://github.com/binary-cats/laravel-rbac)[ Packagist](https://packagist.org/packages/binary-cats/laravel-rbac)[ Docs](https://github.com/binary-cats/laravel-rbac)[ GitHub Sponsors]()[ RSS](/packages/binary-cats-laravel-rbac/feed)WikiDiscussions 2.x Synced 2d ago

READMEChangelog (10)Dependencies (21)Versions (23)Used By (0)

[![](https://camo.githubusercontent.com/2bedf63f24cda7efab02da955dc11fb7ef8a060e2f26b73c33a7aac84529b8a3/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f737570706f72742d756b7261696e652e7376673f743d31)](https://supportukrainenow.org)

[![](https://camo.githubusercontent.com/b1213ae4d10a9e769e16ccaee985b310bc8ea857077919d76fa89907f3881228/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c253230524241432e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d62696e6172792d636174732532466c61726176656c2d72626163267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d4d616e6167652b796f75722b7370617469652532466c61726176656c2d7065726d697373696f6e2b6c697374732b776974682b77656c6c2d646566696e65642b726f6c6573266d643d312673686f7757617465726d61726b3d3126666f6e7453697a653d313030707826696d616765733d6c6f636b2d636c6f736564)](https://camo.githubusercontent.com/b1213ae4d10a9e769e16ccaee985b310bc8ea857077919d76fa89907f3881228/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c253230524241432e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d62696e6172792d636174732532466c61726176656c2d72626163267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d4d616e6167652b796f75722b7370617469652532466c61726176656c2d7065726d697373696f6e2b6c697374732b776974682b77656c6c2d646566696e65642b726f6c6573266d643d312673686f7757617465726d61726b3d3126666f6e7453697a653d313030707826696d616765733d6c6f636b2d636c6f736564)

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

[](#laravel-rbac)

[![Latest Version on Packagist](https://camo.githubusercontent.com/cf80255302e19d3635c748a5f7e2133e2366c51fbad151f4dacc12108af4f511/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f62696e6172792d636174732f6c61726176656c2d726261632e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/binary-cats/laravel-rbac)[![run-tests](https://camo.githubusercontent.com/0071876e115cebb956669c4e60d6051400f8b39f20b191339c0bf5c46d8798c1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f62696e6172792d636174732f6c61726176656c2d726261632f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/binary-cats/laravel-rbac/actions/workflows/run-tests.yml)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/be89e3b798873e1e566d232df9b31745a6a524bfff5cd57f5ba8eba1230e9212/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3737333137313034332f736869656c643f6272616e63683d6d61696e)](https://github.com/binary-cats/laravel-rbac/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)

Enhance your Laravel with opinionated extension for [spatie/laravel-permissions](https://spatie.be/docs/laravel-permission/v6/introduction). Before your permission list grows and maintenance becomes an issue, this package offers simple way of defining roles and their permissions.

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

[](#installation)

You can install the package via composer:

```
composer require binary-cats/laravel-rbac
```

> \*\*N.B. If you are using `spatie/laravel-permission` &lt; version 7, you need to use 1.x version of the package:

```
composer require binary-cats/laravel-rbac:"^1.0"
```

You can publish the config file with:

```
php artisan vendor:publish --tag="rbac-config"
```

This is the contents of the published config file:

```
return [
    /*
    |--------------------------------------------------------------------------
    | Role base access reset control
    |--------------------------------------------------------------------------
    |
    | When running rbac:reset those commands will be executed in sequence
    |
    */

    'jobs' => [
        \BinaryCats\LaravelRbac\Jobs\FlushPermissionCache::class,
        \BinaryCats\LaravelRbac\Jobs\ResetPermissions::class,
        \BinaryCats\LaravelRbac\Jobs\SyncDefinedRoles::class,
    ],

    /*
    |--------------------------------------------------------------------------
    | Role base access ability set
    |--------------------------------------------------------------------------
    |
    | Place your ability files in this folder, and they will be auto discovered
    |
    */
    'path' => app()->path('Abilities'),

    /*
    |--------------------------------------------------------------------------
    | Defined Roles
    |--------------------------------------------------------------------------
    |
    | Defined roles are immutable by users
    |
    */

    'roles' => [

    ],
];
```

You can publish the stub files with:

```
php artisan vendor:publish --tag="rbac-stubs"
```

Usage
-----

[](#usage)

```
php artisan rbac:reset
```

In a simple setup we usually have two basic parts of an RBAC: a permission and a role. Permissions are usually grouped by functional or business logic domain and a Role encapsulates them for a specific guard.

1. [Create Abilities](#abilities)
2. [Define Roles](#defined-roles)
3. [Connect the dots](#connect-the-dots)

### Abilities

[](#abilities)

To avoid collision with `spatie/laravel-permission` we are going to use `BackedEnum` Ability enums to hold out enumerated permissions: You can read more on using `enums` as permissions at the [official docs](https://spatie.be/docs/laravel-permission/v6/basic-usage/enums).

To create an Ability:

```
php artisan make:ability PostAbility
```

This will generate a `PostAbility` in `App\Abilities`:

```
namespace App\Abilities;

enum PostAbility: string
{
    case ViewPost = 'view post';
    case CreatePost = 'create post';
    case UpdatePost = 'update post';
    case DeletePost = 'delete post';
}
```

Default stub contains fairly standard CRUD enumeration, generated using the name of the ability. Feel free to publish the stubs and adjsut as needed.

### Defined Roles

[](#defined-roles)

As the name suggests, a `DefinedRole` offers a mechanism to simplify the definition of all permissions needed for a given role. To create an `EditorRole` run:

```
php artisan make:role EditorRole
```

This will generate an `EditorRole` within `App\Roles`:

```
use BinaryCats\LaravelRbac\DefinedRole;

class EditorRole extends DefinedRole
{
    /** @var array|string[]  */
    protected array $guards = [
        'web'
    ];

    /**
     * List of enumerated permissions for the `web` guard
     *
     * @return array
     */
    public function web(): array
    {
        return [];
    }
}
```

This class contains a (now testable!) configuration definition for the role and its `web` guard. Pretty neat! We can now adjust it like so:

```
namespace App\Roles;

use App\Abilities\PostAbility;
use BinaryCats\LaravelRbac\DefinedRole;

class EditorRole extends DefinedRole
{
    /** @var array|string[]  */
    protected array $guards = [
        'web'
    ];

    /**
     * List of enumerated permissions for the `web` guard
     *
     * @return array
     */
    public function web(): array
    {
        return [
            PostAbility::CreatePost,
            PostAbility::UpdatePost,
            PostAbility::ViewPost,
        ];
    }
}
```

Now you are confident a specific role has specific permissions!

### Connect the dots

[](#connect-the-dots)

Now that we have the abilities and roles, simply register role with `rbac.php` config:

```
    'roles' => [
        \App\Roles\EditorRole::class,
        ...
    ],
```

When you run `rbac:reset` next time, your RBAC will be reset automatically.

Integration
-----------

[](#integration)

I suggest adding the script to `post-autoload-dump` of your `composer.json` to make sure the RBAC is reset on every composer dump:

```
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan rbac:reset"
        ],
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using issue tracker.

Postcardware
------------

[](#postcardware)

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Credits
-------

[](#credits)

- [Cyrill N Kalita](https://github.com/cyrillkalita)
- [All Contributors](../../contributors)

Support us
----------

[](#support-us)

[Binary Cats](https://binarycats.dev) is a webdesign agency based in Illinois, US.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

58

—

FairBetter than 98% of packages

Maintenance90

Actively maintained with recent releases

Popularity42

Moderate usage in the ecosystem

Community15

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 72.2% 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

Every ~51 days

Recently: every ~35 days

Total

16

Last Release

69d ago

Major Versions

1.8.0 → 2.0.02026-03-20

PHP version history (2 changes)1.0.0PHP ^8.2

2.0.0PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/ebb48367388b4368b14cca42714bb13002d7414d9dc8da19c5490ef65c059719?d=identicon)[cyrill.kalita@gmail.com](/maintainers/cyrill.kalita@gmail.com)

---

Top Contributors

[![cyrillkalita](https://avatars.githubusercontent.com/u/2401848?v=4)](https://github.com/cyrillkalita "cyrillkalita (52 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (11 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (6 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (2 commits)")[![briavers](https://avatars.githubusercontent.com/u/26483622?v=4)](https://github.com/briavers "briavers (1 commits)")

---

Tags

laravelenumrbacbinary-cats

###  Code Quality

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/binary-cats-laravel-rbac/health.svg)

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

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k102.4M1.4k](/packages/spatie-laravel-permission)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k3.9M129](/packages/bezhansalleh-filament-shield)[spatie/laravel-passkeys

Use passkeys in your Laravel app

471890.7k39](/packages/spatie-laravel-passkeys)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[masterix21/laravel-licensing

Laravel licensing package with polymorphic assignment to any model, activation keys, expirations/renewals, and seat control via LicenseUsage. Supports offline verification with public-key–signed tokens, a CLI to generate/rotate/revoke keys, and an extensible architecture via config and contracts.

1563.0k4](/packages/masterix21-laravel-licensing)

PHPackages © 2026

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