kiritokatklian / nova-permission

A Laravel Nova tool for Spatie's laravel-permission library
https://novapackages.com/packages/vyuldashev/nova-permission
MIT License
70 stars 16 forks source link

[bug] [V3] Not working in Multi-tenant environment #11

Open mathijsqdrop opened 2 years ago

mathijsqdrop commented 2 years ago

I have a Multi-tenant environment based upon https://tenancyforlaravel.com/saas-boilerplate/ and https://github.com/archtechx/tenancy

In order to make sure that it is clear that tables live in the Central or Tenant "domain" I have to prefix all Central-related tables. This causes the Validator to guess the wrong connection, because of the prefix. In order to combat this, we can either pass the class name to the Validator, so the getConnectionName function is called on the model, which does return the right connection name.

Permissions.php

            Text::make(__('nova-permission-tool::permissions.name'), 'name')
                ->rules(['required', 'string', 'max:255'])
                ->creationRules('unique:'.config('permission.models.permission'))
                ->updateRules('unique:'.config('permission.models.permission').',name,{{resourceId}}'),

and Roles,php

            Text::make(__('nova-permission-tool::roles.name'), 'name')
                ->rules(['required', 'string', 'max:255'])
                ->creationRules('unique:'.config('permission.models.role'))
                ->updateRules('unique:'.config('permission.models.role').',name,{{resourceId}}'),

This fixes the problem (at least for me) 😄

PHP 8.1.5
Laravel Framework 9.10.1
Laravel Nova v3.32.0
kiritokatklian/nova-permission v3.2.2
kiritokatklian commented 2 years ago

@mathijsqdrop I see. I don't use Tenancy and I don't think I'll be able to setup a test environment to test this anytime soon. Could you please open a PR with the solution that worked for you?