Download the PHP package graphene-ict/nova-permissions without Composer
On this page you can find all versions of the php package graphene-ict/nova-permissions. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download graphene-ict/nova-permissions
More information about graphene-ict/nova-permissions
Files in graphene-ict/nova-permissions
Package nova-permissions
Short Description Nova Permissions tool based on spatie permissions
License MIT
Informations about the package nova-permissions
Laravel Nova Permissions
Nova Permissions tool based on spatie permissions
We have a Migration, Seed, Policy and Resource ready for a good Authorization Experience.
- Installation
- Database Migration
- Configuration
- Database Seeding
- Permissions
- Detail View
- Edit View
- Create a Model Policy
- Scope Resource for User
- Customization
- Use your own Resources
- Credits
Installation
You can install the package in to a Laravel app that uses Nova via composer:
Database Migration
Publish the Migration with the following command:
Migrate the Database:
Configuration
You must register the tool with Nova. This is typically done in the tools
method of the NovaServiceProvider
.
Finally, add MorphToMany
fields to you app/Nova/User
resource:
Add the Spatie\Permission\Traits\HasRoles trait to your User model(s):
Database Seeding
Publish our Seeder with the following command:
Before you do any seeding admin email parametar in your env
This is just an example on how you could seed your Database with Roles and Permissions. Modify RolesAndPermissionsSeeder.php
in database/seeds
. List all your Models you want to have Permissions for in the $collection
Array.
Create a role and attach permissions to it:
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.
Permissions
Detail View
Edit View
Create a Model Policy
You can extend GrapheneICT\NovaPermissions\Policies\Policy
and have a very clean Model Policy that works with Nova.
For Example: Create a new User Policy with php artisan make:policy UserPolicy
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
view users, view own users, manage users, manage own users, restore users, forceDelete users
as Permissions in your Table in order to extend our Policy.
view own users
is superior toview users
and allows the User to only view his own Users.
manage own users
is superior tomanage users
and allows the User to only manage his own Users.
Scope Resource for User
If you use our Policy and Seeder, the user will still be able to see other Entries. In order to only allow a User to view his own Entries and no others, you can extens our GrapheneICT\NovaPermissions\Nova\ResourceForUser
Class like this:
Note: ResourceForUser assumes the Resource has a
user_id
column in the Database. If you are using another column, feel free to copy the contents of the Resource and modify it.
Customization
Use your own Resources
If you want to use your own resource classes, you can define them when you register the tool:
Credits
This Package is inspired by eminiarts/nova-permission