opscale-co/nova-authorization

Secure your Nova resources with roles and permissions

1.0.0 2025-03-26 16:12 UTC

This package is auto-updated.

Last update: 2025-03-26 17:28:34 UTC


README

Support Opscale

At Opscale, we’re passionate about contributing to the open-source community by providing solutions that help businesses scale efficiently. If you’ve found our tools helpful, here are a few ways you can show your support:

Star this repository to help others discover our work and be part of our growing community. Every star makes a difference!

💬 Share your experience by leaving a review on Trustpilot or sharing your thoughts on social media. Your feedback helps us improve and grow!

📧 Send us feedback on what we can improve at feedback@opscale.co. We value your input to make our tools even better for everyone.

🙏 Get involved by actively contributing to our open-source repositories. Your participation benefits the entire community and helps push the boundaries of what’s possible.

💼 Hire us if you need custom dashboards, admin panels, internal tools or MVPs tailored to your business. With our expertise, we can help you systematize operations or enhance your existing product. Contact us at hire@opscale.co to discuss your project needs.

Thanks for helping Opscale continue to scale! 🚀

Description

Secure your Nova resources with roles and permissions.

One of the most basic needs for a dashboard is differentiated user access, allowing each profile to manage and view specific information. Confidently manage access to your data with roles and permissions.

Role creation Role demo

Installation

Latest Version on Packagist

You can install the package in to a Laravel app that uses Nova via composer:

composer require opscale-co/nova-authorization

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 \Opscale\NovaAuthorization\Tool(),
    ];
}

This package uses Spatie Permissions internally to manage roles and permissions structure. Follow the installation instructions for this package.

Then modify the following items in Spatie permissions configuration file (permissions.php):

'permission' => Opscale\NovaAuthorization\Models\Permission::class, 'role' => Opscale\NovaAuthorization\Models\Role::class, 'register_permission_check_method' => false,

Important

This packages uses its own cache strategy, so we need to disable the default behavior with register_permission_check_method.

Then add the roles relationship to your User resource:

// in app/Nova/User.php
// ...
public function fields()
{
    return [
        // ...
        new Tag::make(_('Roles'), 'roles'),
    ];
}

Usage

You will see a "Roles" item in your menu by default. You can create your roles here and assign them to users.

You can also aumate the initial permissions setup using our built-in commands:

  • php artisan authorization:create-permissions to automatically read all your resources and create the related permissions
  • php artisan authorization:create-role to create a role assigning the selected permissions
  • php artisan authorization:assign-role to assign an existing role for an user
  • php artisan authorization:super-admin to assign all permission to an user
  • php artisan authorization:clear-cache to clear the permissions cache for users (Recommended to execute as part of deployment pipelines)

Testing

npm run test

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 development@opscale.co instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.