Silvanite / novatoolpermissions

Laravel Nova Permissions Tool (User, Roles and Permissions / Access Control (ACL))
MIT License
101 stars 33 forks source link

Allow override of Nova resource #39

Open Senexis opened 5 years ago

Senexis commented 5 years ago

First off, this issue is related to #24 in that I wish to be able to override the default Nova resource injected via NovaToolPermissions.php. This shouldn't need any publishing, however, as per the way class extending works. I currently did this in my local project by doing something like this:

class NovaToolPermissions extends Tool
{
    /**
     * Perform any tasks that need to happen when the tool is booted.
     *
     * @return void
     */
    public function boot()
    {
        if (config('novatoolpermissions.useDefaultResource', true)) {
            Nova::resources([
                Role::class,
            ]);
        }
    }
}

Now, this works fine for my use case, which is a relatively small application. I have not tested this on larger applications, but I imagine that due to this logic being in the boot() method, it doesn't impact the performance of Nova in any meaningful way.

This allows me to then extend the base role resource and extend it to my heart's content in /app/nova/ much like the following. Special shout-out to issue #30 here. šŸ˜‰

use Silvanite\NovaToolPermissions\Role as BaseRole;

class Role extends BaseRole
{
    /**
     * The logical group associated with the resource.
     *
     * @var string
     */
    public static function group()
    {
        return __('Administration');
    }

    // More customization...
}

I would like to propose this being implemented in a similar form in the production tool, as it very simply allows any customization or overrides without having to constantly rely on, well, you guys. šŸ™‚

Thank you for maybe considering this. I would much appreciate it.

preliot commented 5 years ago

Really would like something like this as well. I want to customize some code for a super admin, but this is currently impossible. Would be nice if we could inject the resource into the boot method:

/**

m2de commented 5 years ago

Thanks for the feedback. Sounds like a sensible suggestion but instead of the useDefaultResource config it might be better to just specify the fully name spaced class to be used there. Will try and get to this as soon as I can but if anyone else wants to open a PR that would be appreciated too.