Download the PHP package sereny/nova-permissions without Composer
On this page you can find all versions of the php package sereny/nova-permissions. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sereny/nova-permissions
More information about sereny/nova-permissions
Files in sereny/nova-permissions
Package nova-permissions
Short Description Laravel Nova 4 Grouped Permissions
License MIT
Informations about the package nova-permissions
Laravel Nova - Roles & Permissions
A Laravel Nova Tool that allows you to group your Permissions and attach it to Users. It uses Spatie's laravel-permission.
We have a Migration, Seed, Policy and Resource ready for a good Authorization Experience.
- Installation
- Permissions with Groups
- Index view
- Detail View
- Edit View
- Database Seeding
- Create a Model Policy
- Super Admin
- Customization
- Credits
Installation
You can install the package in to a Laravel app that uses Nova via composer:
Publish the Migration with the following command:
Migrate the Database:
Next up, you must register the tool with Nova. This is typically done in the tools
method of the NovaServiceProvider
.
If you want to hide the tool from certain users, you can write your custom logic for the ability to see the tool:
Finally, add MorphToMany
fields to your app/Nova/User
resource:
Add the Spatie\Permission\Traits\HasRoles
trait to your User model(s):
A new menu item called Roles & Permissions will appear in your Nova app after installing this package.
Permissions with Groups
Index View
Detail View
Edit View
Database Seeding
Publish our Seeder with the following command:
This is just an example on how you could seed your Database with Roles and Permissions. Modify RolesAndPermissionsSeeder.php
in database/seeders
. List all your Models you want to have Permissions for in the $collection
Array and change the email for the Super-Admin:
Now you can seed the Database. Add $this->call(RolesAndPermissionsSeeder::class);
to the DatabaseSeeder
.
Note: If this doesn't work, run
composer dumpautoload
to autoload the Seeder.
Create a Model Policy
You can extend Sereny\NovaPermissions\Policies\BasePolicy
and have a very clean Model Policy that works with Nova.
For Example: Create a new Contact Policy with php artisan make:policy ContactPolicy
with the following code:
It should now work as exptected. Just create a Role, modify its Permissions and the Policy should take care of the rest.
Note: Don't forget to add your Policy to your
$policies
inApp\Providers\AuthServiceProvider
.Note: Only extend the Policy if you have created your Permissions according to our Seeding Example. Otherwise, make sure to have
viewAnyContact, viewContact, createContact, updateContact, deleteContact, restoreContact, destroyContact
as Permissions in your Table in order to extend our Policy.
Super Admin
A Super Admin can do everything. If you extend our Policy, make sure to add a isSuperAdmin()
Function to your App\User
Model:
Customizations
Important
To customize the Role
model you need to use Sereny\NovaPermissions\Traits\SupportsRole
trait:
Credits
This Package is inspired by eminiarts/nova-permissions.
A huge thanks goes to Spatie spatie/laravel-permission for their amazing work!