{"id":21870951,"url":"https://github.com/grapheneict/nova-permissions","last_synced_at":"2025-06-15T00:33:19.261Z","repository":{"id":39794406,"uuid":"276034152","full_name":"GrapheneICT/nova-permissions","owner":"GrapheneICT","description":"Nova Permissions tool based on spatie permissions","archived":false,"fork":false,"pushed_at":"2022-09-24T17:45:20.000Z","size":257,"stargazers_count":9,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-16T13:58:59.412Z","etag":null,"topics":["laravel","laravel-nova","php","vue"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GrapheneICT.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-30T07:53:52.000Z","updated_at":"2022-11-11T20:18:20.000Z","dependencies_parsed_at":"2022-09-15T23:01:19.946Z","dependency_job_id":null,"html_url":"https://github.com/GrapheneICT/nova-permissions","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/GrapheneICT/nova-permissions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GrapheneICT%2Fnova-permissions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GrapheneICT%2Fnova-permissions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GrapheneICT%2Fnova-permissions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GrapheneICT%2Fnova-permissions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GrapheneICT","download_url":"https://codeload.github.com/GrapheneICT/nova-permissions/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GrapheneICT%2Fnova-permissions/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259905372,"owners_count":22929916,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","laravel-nova","php","vue"],"created_at":"2024-11-28T06:13:02.368Z","updated_at":"2025-06-15T00:33:19.233Z","avatar_url":"https://github.com/GrapheneICT.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Nova Permissions\n\nNova Permissions tool based on spatie permissions\n\nWe have a Migration, Seed, Policy and Resource ready for a good Authorization Experience.\n\n![image](https://user-images.githubusercontent.com/22980168/86119518-ec628700-bad2-11ea-9724-03f25eaba41e.PNG)\n\n1. [Installation](#Installation)\n    * [Database Migration](#database-migration)\n    * [Configuration](#configuration)\n    * [Database Seeding](#database-seeding)\n2. [Permissions](#permissions)\n    * [Detail View](#detail-view)\n    * [Edit View](#edit-view)\n    * [Create a Model Policy](#create-a-model-policy)\n    * [Scope Resource for User](#scope-resource-for-user)\n3. [Customization](#customization)\n    * [Use your own Resources](#use-your-own-resources)\n4. [Credits](#credits)\n\n## Installation\n\nYou can install the package in to a Laravel app that uses [Nova](https://nova.laravel.com) via composer:\n```bash\ncomposer require graphene-ict/nova-permissions\n```\n\n### Database Migration\n\nPublish the Migration with the following command:\n\n```bash\nphp artisan vendor:publish --provider=\"GrapheneICT\\NovaPermissions\\ToolServiceProvider\" --tag=\"migrations\"\n```\n\nMigrate the Database:\n\n```bash\nphp artisan migrate\n```\n\n### Configuration\n\nYou must register the tool with Nova. This is typically done in the `tools` method of the `NovaServiceProvider`.\n\n```php\n// in app/Providers/NovaServiceProvider.php\n\n// ...\n\npublic function tools()\n{\n    return [\n        // ...\n        new \\GrapheneICT\\NovaPermissions\\NovaPermissions(),\n    ];\n}\n```\n\nFinally, add `MorphToMany` fields to you `app/Nova/User` resource:\n\n```php\n// ...\nuse Laravel\\Nova\\Fields\\MorphToMany;\n\npublic function fields(Request $request)\n{\n    return [\n        // ...\n        MorphToMany::make('Roles', 'roles', \\GrapheneICT\\NovaPermissions\\Nova\\Role::class),\n        MorphToMany::make('Permissions', 'permissions', \\GrapheneICT\\NovaPermissions\\Nova\\Permission::class),\n    ];\n}\n```\n\nAdd  the Spatie\\Permission\\Traits\\HasRoles trait to your User model(s):\n\n```php\nuse Illuminate\\Foundation\\Auth\\User as Authenticatable;\nuse Spatie\\Permission\\Traits\\HasRoles;\n\nclass User extends Authenticatable\n{\n    use HasRoles;\n\n    // ...\n}\n```\n\n### Database Seeding\n\nPublish our Seeder with the following command:\n\n```\nphp artisan vendor:publish --provider=\"GrapheneICT\\NovaPermissions\\ToolServiceProvider\" --tag=\"seeds\"\n```\n\nBefore you do any seeding admin email parametar in  your env\n\n```env\nNOVA_PERMISSION_ADMIN_EMAIL = your@email.com\n```\n\nThis 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.\nCreate a role and attach permissions to it:\n\n```php\nclass RolesAndPermissionsSeeder extends Seeder\n{\n    /**\n     * Run the database seeds.\n     *\n     * @return void\n     */\n    public function run()\n    {\n        // Reset cached roles and permissions\n        app()[PermissionRegistrar::class]-\u003eforgetCachedPermissions();\n\n        $collection = collect([\n            User::class,\n            Role::class,\n            Permission::class,\n            // ... // List all your Models you want to have Permissions for.\n        ]);\n\n        $adminEmail = env('NOVA_PERMISSION_ADMIN_EMAIL', null);\n\n        if (is_null($adminEmail)) {\n            throw new \\InvalidArgumentException('Email parameter must be provided!');\n        }\n\n        // Create an Admin Role and assign all Permissions\n        $role = Role::create(['name' =\u003e 'admin']);\n        $role-\u003egivePermissionTo(Permission::all());\n\n       // Give User Admin Role\n         $user = User::whereEmail($adminEmail)-\u003efirst(); // Change this to your email.\n         $user-\u003eassignRole('admin');\n    }\n}\n```\n\nNow you can seed the Database. Add `$this-\u003ecall(RolesAndPermissionsSeeder::class);` to the `DatabaseSeeder`.\n\n\u003e **Note**: If this doesn't work, run `composer dumpautoload` to autoload the Seeder.\n\n## Permissions\n\n### Detail View\n![grap1](https://user-images.githubusercontent.com/22980168/86581659-aef17400-bf80-11ea-897d-f00952e1b2cc.PNG)\n\n### Edit View\n![grap2](https://user-images.githubusercontent.com/22980168/86581690-bf095380-bf80-11ea-85fc-3f06d2873547.PNG)\n\n### Create a Model Policy\n\nYou can extend `GrapheneICT\\NovaPermissions\\Policies\\Policy` and have a very clean Model Policy that works with Nova.\n\nFor Example: Create a new User Policy with `php artisan make:policy UserPolicy` with the following code:\n\n```php\nclass UserPolicy extends Policy\n{\n    /**\n     * The Permission key the Policy corresponds to.\n     *\n     * @var string\n     */\n    public static $key = 'users';\n}\n```\n\nIt should now work as exptected. Just create a Role, modify its Permissions and the Policy should take care of the rest.\n\n\u003e **Note**: Don't forget to add your Policy to your `$policies` in `App\\Providers\\AuthServiceProvider`.\n\n\u003e **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.\n\n\u003e `view own users` is superior to `view users` and allows the User to only view his own Users.\n\n\u003e `manage own users` is superior to `manage users` and allows the User to only manage his own Users.\n\n### Scope Resource for User\n\nIf 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:\n\n```php\nclass User extends ResourceForUser \n{\n    //...\n}\n```\n\n\u003e **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.\n\n## Customization\n\n### Use your own Resources\n\nIf you want to use your own resource classes, you can define them when you register the tool:\n\n```php\n// in app/Providers/NovaServiceProvider.php\n\n// ...\n\npublic function tools()\n{\n    return [\n        // ...\n        \\GrapheneICT\\NovaPermissions\\NovaPermissionTool::make()\n            -\u003eroleResource(Role::class)\n            -\u003epermissionResource(Permission::class),\n    ];\n}\n```\n\n## Credits\n\nThis Package is inspired by [eminiarts/nova-permission](https://novapackages.com/packages/eminiarts/nova-permissions)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrapheneict%2Fnova-permissions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrapheneict%2Fnova-permissions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrapheneict%2Fnova-permissions/lists"}