Giter Site home page Giter Site logo

tyler-rehm / nova-permission Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vyuldashev/nova-permission

0.0 0.0 0.0 1.15 MB

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

Home Page: https://novapackages.com/packages/vyuldashev/nova-permission

PHP 100.00%

nova-permission's Introduction

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

Latest Version on Packagist Total Downloads

screenshot 1

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),
    ];
}

Or if you want to attach multiple permissions at once, use RoleBooleanGroup and PermissionBooleanGroup fields (requires at least Nova 2.6.0):

// ...
use Vyuldashev\NovaPermission\PermissionBooleanGroup;
use Vyuldashev\NovaPermission\RoleBooleanGroup;

public function fields(Request $request)
{
    return [
        // ...
        RoleBooleanGroup::make('Roles'),
        PermissionBooleanGroup::make('Permissions'),
    ];
}

If your User could have a single role at any given time, you can use RoleSelect field. This field will render a standard select where you can pick a single role from.

// ...
use Vyuldashev\NovaPermission\PermissionBooleanGroup;
use Vyuldashev\NovaPermission\RoleSelect;

public function fields(Request $request)
{
    return [
        // ...
        RoleSelect::make('Role', 'roles'),
    ];
}

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),
    ];
}

If you want to show your roles and policies with a custom label, you can set $labelAttribute when instantiating your fields:

// ...
use Vyuldashev\NovaPermission\PermissionBooleanGroup;
use Vyuldashev\NovaPermission\RoleSelect;

public function fields(Request $request)
{
    return [
        // ...
        RoleBooleanGroup::make('Roles', 'roles', null, 'description'),
        PermissionBooleanGroup::make('Permissions', 'permissions', null, 'description'),
        RoleSelect::make('Role', 'roles', null, 'description'),
    ];
}

Define Policies

// in app/Providers/NovaServiceProvider.php

// ...

public function tools()
{
    return [
        // ...
        \Vyuldashev\NovaPermission\NovaPermissionTool::make()
            ->rolePolicy(RolePolicy::class)
            ->permissionPolicy(PermissionPolicy::class),
    ];
}

Usage

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

nova-permission's People

Contributors

vyuldashev avatar nalingia avatar sp4r74cus avatar reflow1319 avatar gnanakeethan avatar shalawani avatar siebeve avatar letrams avatar johnpaulmedina avatar igedeon avatar erhansogut avatar drbyte avatar dnwjn avatar dercodercom avatar astalpaert avatar nero2k avatar vincenzoraco avatar stylecibot avatar sadeghpm avatar rvxlab avatar pabloguerrez avatar melvintehu avatar marcorivm avatar lucascolette avatar fkeloks avatar f-liva avatar dividy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.