Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use config models #139

Merged
merged 2 commits into from
Nov 8, 2022

Conversation

FurkanGM
Copy link
Contributor

When extend role or permission model, we should use the model specified in the config so that we do not get errors in filament dashboard or commands.

Example extend, uuid based role and permission https://spatie.be/docs/laravel-permission/v5/advanced-usage/uuid

@bezhanSalleh
Copy link
Owner

hey, could you check it out with v2.3.0 and see there is no issue and resolve the custom models from Utils instead of the FilamentShield and let me know... thanks

@FurkanGM
Copy link
Contributor Author

FurkanGM commented Nov 1, 2022

Hi, I merged and tested v2.3.0. I didn't have any problems. You can review :)

@Z3d0X
Copy link

Z3d0X commented Nov 2, 2022

Not sure if this is better, but just stating this is possible ✌️

use Spatie\Permission\PermissionRegistrar;
app(PermissionRegistrar::class)->getPermissionClass();

use Spatie\Permission\Contracts\Permission;
app(Permission::class);

@bezhanSalleh
Copy link
Owner

Not sure if this is better, but just stating this is possible ✌️

use Spatie\Permission\PermissionRegistrar;
app(PermissionRegistrar::class)->getPermissionClass();

use Spatie\Permission\Contracts\Permission;
app(Permission::class);

yeah i know, the reason i asked @FurkanGM to resolve the models via utils was, we can set Permission and Role class through the PermissionRegistrar as well;

use Spatie\Permission\PermissionRegistrar;

app(PermissionRegistrar::class)
   ->setPermissionClass(MyCustomePermission::class)
   ->setRoleClass(MyCustomRole::class);

anyhow, now we can easily turn this:

    public static function getRoleModel(): string
    {
        return config('permission.models.role');
    }

    public static function getPermissionModel(): string
    {
        return config('permission.models.permission');
    }

into :

   use Spatie\Permission\PermissionRegistrar;
   
    public static function getRoleModel(): string
    {
        return app(PermissionRegistrar::class)->getRoleClass();
    }

    public static function getPermissionModel(): string
    {
        return app(PermissionRegistrar::class)->getPermissionClass();
    }

so now if someone changes the models through config or permission registrar, either way we will be covered.

@bezhanSalleh bezhanSalleh merged commit 564ad12 into bezhanSalleh:main Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants