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
- Guard Name Filter
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
.
Click on the "Access Control" menu item in your Nova app to see the tool provided by this package.
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.
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.
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}
.
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.