Skip to content
A Laravel Nova tool for Spatie's laravel-permission library
Branch: master
Clone or download
vyuldashev Merge pull request #73 from s950329/master
Translation for Chinese and Traditional Chinese
Latest commit eb5c517 Apr 9, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs add screenshots Aug 23, 2018
resources Add Chinese Translation Mar 24, 2019
src fix #59 Dec 19, 2018
.editorconfig wip Aug 23, 2018
.gitattributes wip Aug 23, 2018
.gitignore
.scrutinizer.yml
.styleci.yml wip Aug 23, 2018
README.md fix #43 Dec 18, 2018
composer.json fix composer.json php version constraint Sep 27, 2018

README.md

A Laravel Nova tool for Spatie's laravel-permission library

Latest Version on Packagist Total Downloads

screenshot 1 screenshot 2 screenshot 3

Installation

You can install the package in to a Laravel app that uses Nova via composer:

composer require vyuldashev/nova-permission

Go through the Installation section in order to setup laravel-permission.

Next up, you must register the tool with Nova. This is typically done in the tools method of the NovaServiceProvider.

// in app/Providers/NovaServiceProvider.php

// ...

public function tools()
{
    return [
        // ...
        \Vyuldashev\NovaPermission\NovaPermissionTool::make(),
    ];
}

Next, add middleware to config/nova.php

// in config/nova.php
'middleware' => [
    // ...
    \Vyuldashev\NovaPermission\ForgetCachedPermissions::class,
],

Finally, add MorphToMany fields to you app/Nova/User resource:

// ...
use Laravel\Nova\Fields\MorphToMany;

public function fields(Request $request)
{
    return [
        // ...
        MorphToMany::make('Roles', 'roles', \Vyuldashev\NovaPermission\Role::class),
        MorphToMany::make('Permissions', 'permissions', \Vyuldashev\NovaPermission\Permission::class),
    ];
}

Customization

If you want to use custom resource classes you can define them when you register a tool:

// in app/Providers/NovaServiceProvider.php

// ...

public function tools()
{
    return [
        // ...
        \Vyuldashev\NovaPermission\NovaPermissionTool::make()
            ->roleResource(CustomRole::class)
            ->permissionResource(CustomPermission::class),
    ];
}

Usage

A new menu item called "Permissions & Roles" will appear in your Nova app after installing this package.

You can’t perform that action at this time.