lizhineng / nova-permission-tool
A Laravel Nova tool based on Spatie permission package.
Installs: 5 409
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 2
Open Issues: 1
Requires
- php: ^7.2
- spatie/laravel-permission: ^3.0
This package is auto-updated.
Last update: 2024-11-04 10:25:45 UTC
README
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
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.