PHPackages                             bbs-lab/nova-permission - 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. bbs-lab/nova-permission

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

bbs-lab/nova-permission
=======================

Manage roles and permissions in Laravel Nova with a visual permission builder, per-instance (granular) permissions and a super-admin override, built on spatie/laravel-permission.

v2.0.0(3w ago)69.2k↑100%3[1 PRs](https://github.com/BBS-Lab/nova-permission/pulls)MITPHPPHP ^8.2CI failing

Since Nov 21Pushed 3w ago6 watchersCompare

[ Source](https://github.com/BBS-Lab/nova-permission)[ Packagist](https://packagist.org/packages/bbs-lab/nova-permission)[ Docs](https://github.com/BBS-Lab/nova-permission)[ RSS](/packages/bbs-lab-nova-permission/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (10)Dependencies (35)Versions (15)Used By (0)

Laravel Nova permission tool
============================

[](#laravel-nova-permission-tool)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3b5ed6bea1b6cd6167681198a54c2806b4225b030a9d59c18f43901039dced0f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6262732d6c61622f6e6f76612d7065726d697373696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bbs-lab/nova-permission)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Tests](https://camo.githubusercontent.com/f4ed5cd890c530a15993d3d30e4843537c28b16d74d0b8d586ead4a4d7de519f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f4242532d4c61622f6e6f76612d7065726d697373696f6e2f72756e2d74657374732e796d6c3f6272616e63683d6d6173746572266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/BBS-Lab/nova-permission/actions/workflows/run-tests.yml)[![PHPStan](https://camo.githubusercontent.com/c6446b579a0437be48bf5708d5f5d8b2c97d8ee9fe198026fa30462f3b1260a7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f4242532d4c61622f6e6f76612d7065726d697373696f6e2f7068707374616e2e796d6c3f6272616e63683d6d6173746572266c6162656c3d7068707374616e267374796c653d666c61742d737175617265)](https://github.com/BBS-Lab/nova-permission/actions/workflows/phpstan.yml)[![Total Downloads](https://camo.githubusercontent.com/fd95ebbb18dca3c4115df0143b323c68e8aa9b9ed10a21db4cd2af994e8f6d73/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6262732d6c61622f6e6f76612d7065726d697373696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bbs-lab/nova-permission)

Based on [spatie/permission](https://github.com/spatie/laravel-permission), this tool gives you ability to manage roles and permission. The tool provides permission builder.

[![permission builder](art/permission-builder.png)](art/permission-builder.png)

Contents
--------

[](#contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
    - [Generate permissions](#generate-permissions)
    - [Protect resources](#protect-resources)
    - [Granular permissions](#granular-permissions)
    - [Caching](#caching)
    - [Super admin](#super-admin)
- [Testing](#testing)
- [Changelog](#changelog)
- [Security](#security)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)

Requirements
------------

[](#requirements)

- PHP `^8.2`
- Laravel Nova `^4.0 || ^5.0`
- spatie/laravel-permission `^6.0`
- Laravel `^11.0 || ^12.0 || ^13.0`

Both Nova majors are exercised in CI. Note that **Nova 4** (through its `inertiajs/inertia-laravel`dependency) tops out at **PHP 8.4** and **Laravel 11**; on PHP 8.5 or Laravel 12+, use Nova 5. Composer resolves the right combination for you.

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

[](#installation)

To get started, you will need to install the following dependencies

```
composer require bbs-lab/nova-permission
```

The service provider will automatically get registered. Or you may manually add the service provider in your `config/app.php` file:

```
'providers' => [
    // ...
    BBSLab\NovaPermission\NovaPermissionServiceProvider::class,
],
```

Publish Spatie's permission migration (the base `permissions`/`roles` tables):

```
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="permission-migrations"
```

This package's own migrations (which add the `group` + polymorphic `authorizable` columns and the `override_permission` flag) run automatically with `php artisan migrate` — you do not need to publish them.

You can publish the config files with:

```
php artisan vendor:publish --tag="nova-permission-config"
```

This publishes two files. `config/permission.php` is [Spatie's standard configuration](https://spatie.be/docs/laravel-permission) — the only change this package needs is to point the two model bindings at its own models (which implement the package contracts):

```
// config/permission.php (only the keys this package changes; the rest is Spatie's default)
return [

    'models' => [

        /*
         * When using the "HasPermissions" trait from this package, we need to know which
         * Eloquent model should be used to retrieve your permissions. Of course, it
         * is often just the "Permission" model but you may use whatever you like.
         *
         * The model you want to use as a Permission model needs to implement the
         * `BBSLab\NovaPermission\Contracts\Permission` contract.
         */

        'permission' => BBSLab\NovaPermission\Models\Permission::class,

        /*
         * When using the "HasRoles" trait from this package, we need to know which
         * Eloquent model should be used to retrieve your roles. Of course, it
         * is often just the "Role" model but you may use whatever you like.
         *
         * The model you want to use as a Role model needs to implement the
         * `BBSLab\NovaPermission\Contracts\Role` contract.
         */

        'role' => BBSLab\NovaPermission\Models\Role::class,

    ],

    // `table_names`, `column_names`, `display_permission_in_exception` and `cache`
    // keep Spatie's defaults — leave them as published unless you have a reason to change them.
];
```

```
// config/nova-permission.php
return [
    // Resources whose individual records can carry their own permissions
    // (see "Granular permissions" below). Leave empty if you only use
    // general, model-wide permissions.
    'authorizable_models' => [
        // \App\Nova\Post::class,
    ],

    // Resources excluded from `nova-permission:generate`.
    'generate_without_resources' => [
        \Laravel\Nova\Actions\ActionResource::class,
    ],

    // Authorization gate cache. Disabled by default — enable it only when the
    // read volume justifies it and you accept the staleness window (entries are
    // invalidated on permission save/delete). `ttl` is the lifetime in seconds.
    'cache' => [
        'enabled' => env('NOVA_PERMISSION_CACHE', false),
        'ttl' => env('NOVA_PERMISSION_CACHE_TTL', 60 * 60),
    ],
];
```

Then create the tables by running the migrations (Spatie's published migration plus this package's auto-registered ones):

```
php artisan migrate
```

Usage
-----

[](#usage)

You must register the tool with Nova. This is typically done in the `tools` method of the `NovaServiceProvider`:

```
// app/Providers/NovaServiceProvider.php
