Skip to content

lizhineng/nova-permission-tool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Nova Permission Tool

Latest Version on Packagist Total Downloads StyleCI MIT license

This is a Laravel Nova tool based on Spatie permission package which lets you:

  • List all roles and permissions
  • List permissions by role
  • List roles by permissions
  • List users by roles & permissions
  • CRUD roles & permissions

Built-in filters

  • Guard Name Filter

screenshot of the permission tool

Installation

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

composer require lizhineng/nova-permission-tool

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 [
        // ...
        new \Lizhineng\PermissionTool\PermissionTool,
    ];
}

You can publish the lang files and config file with:

php artisan vendor:publish --provider="Lizhineng\PermissionTool\ToolServiceProvider"

When published, the config file is located at /config/permission-tool.php, and the lang files are localed at /resource/lang/vendor/permission-tool.

Usage

Click on the "Access Control" menu item in your Nova app to see the tool provided by this package.

Config

Currently there is only one option can be edited in this package.

When you checkout the role/permission resource detail page, it will show you the users who has the role/permission below. The models.user option is to tell us which Eloquent model should be used to retrieve your users, and it must be a Laravel Nova resource model.

Attach to users detail page

Thanks to Nova, that's pretty easy to attach roles fields or permissions fields to users detail page.

// in app/Nova/User.php

// ...

public function fields()
{
    return [
        // ...

        MorphToMany::make('Roles', 'roles', \Lizhineng\PermissionTool\Role::class),

        MorphToMany::make('Permissions', 'permissions', \Lizhineng\PermissionTool\Permission::class),
    ];
}

And don't forget to use Spatie\Permission\Traits\HasRoles trait to your User model.

Localization

The package is supported the following languages:

  • English
  • Simplified Chinese

When you publish the package lang files, you can make your own translation in /resource/vendor/permission-tool/{locale}.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email lizhineng@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.