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

ActiveLibrary

afurgeri/laravel-rbac
=====================

Roles, permissions, and permission middleware for Laravel applications.

v0.5.0(3w ago)035MITPHPPHP ^8.3CI passing

Since Jul 17Pushed 1w agoCompare

[ Source](https://github.com/afurgeri/laravel-rbac)[ Packagist](https://packagist.org/packages/afurgeri/laravel-rbac)[ RSS](/packages/afurgeri-laravel-rbac/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (16)Versions (18)Used By (0)

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

[](#laravel-rbac)

Roles, permissions, role assignment, and permission middleware for Laravel applications. The package depends on [`afurgeri/laravel-crud`](https://github.com/afurgeri/laravel-crud) for reusable CRUD definitions.

Scope
-----

[](#scope)

This package provides the reusable RBAC core:

- SQL and MongoDB role and permission models;
- `HasRoles` and `HasPermissions` integration contracts;
- permission middleware;
- configurable RBAC tables and user model;
- migrations and permission seeders;
- role authorization through Laravel policies;
- optional CRUD integration for the `Role` model.

Resource-specific user CRUD, Inertia controllers, routes, navigation, and Vue pages belong in the consuming application.

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

[](#installation)

```
composer require afurgeri/laravel-rbac
```

Both the RBAC and CRUD service providers are registered through Laravel package discovery.

After installing both packages, generate the application integration with:

```
php artisan crud:install
php artisan rbac:install --database=mysql
```

`rbac:install` generates the user/role CRUD definitions, controllers, policy, routes, and Inertia/Vue pages. It requires the generic CRUD frontend files from `crud:install` and reports the required `User` model integration without modifying the model automatically.

For MongoDB, install the official driver in the consuming application and select the MongoDB integration stubs:

```
composer require mongodb/laravel-mongodb
php artisan rbac:install --database=mongodb
```

The installer generates explicit `Role` and `Permission` model configuration for the selected connector. It does not generate or modify the application's authenticatable `User` model.

If Packagist is temporarily unavailable, add the GitHub repositories as temporary VCS sources:

```
{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/afurgeri/laravel-crud"
        },
        {
            "type": "vcs",
            "url": "https://github.com/afurgeri/laravel-rbac"
        }
    ]
}
```

Then require the tagged versions:

```
composer require afurgeri/laravel-crud:^0.4 afurgeri/laravel-rbac:^0.3
```

Full MongoDB application
------------------------

[](#full-mongodb-application)

Selecting `--database=mongodb` configures the RBAC role and permission models, but it cannot replace the application's `User` model automatically. For a fully MongoDB-backed application, the authenticatable model must use the MongoDB authentication base class and the RBAC trait:

```
