bezhanSalleh / filament-shield

The easiest and most intuitive way to add access management to your Filament Admin Resources, Pages & Widgets through `spatie/laravel-permission`

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to transfer RoleResource.php in Clusters?

free-storage opened this issue · comments

How to transfer correctly
app/Filament/Resources/Shield/RoleResource.php
in
app/Filament/Clusters/Settings/Resources/Shield/RoleResource.php
?

The plugin has this method in https://github.com/bezhanSalleh/filament-shield/blob/3.x/src/Support/Utils.php#L18:

    public static function isResourcePublished(): bool
    {
        $roleResourcePath = app_path((string) Str::of('Filament\\Resources\\Shield\\RoleResource.php')->replace('\\', '/'));

        $filesystem = new Filesystem();

        return (bool) $filesystem->exists($roleResourcePath);
    }

If I transfer, the plugin will not correctly determine the location of the resource.

Just register your cluster class in the shield config.

Just register your cluster class in the shield config.

Yes, but the file will remain in the same location app/Filament/Resources/Shield/RoleResource.php. I want to move the file here app/Filament/Clusters/Settings/Resources/Shield/RoleResource.php to keep the application structure.

You need to modify $roleResourcePath = app_path((string) Str::of('Filament\\Resources\\Shield\\RoleResource.php')->replace('\\', '/')); in isResourcePublished() and add the path to the cluster if it is specified in the config. Do a check either here or there.

Keeping the structure as recommended is for your own application not plugins.

Keeping the structure as recommended is for your own application not plugins.

I modified RoleResource.php so it is part of my application. So I want to place it in the right place.

Can you improve isResourcePublished() so that it additionally checks against the specified cluster? This will solve the problem. Because if you move RoleResource.php to the directory with the cluster, then the condition will break here and your script will connect the standard resource https://github.com/bezhanSalleh/filament-shield/blob/3.x/src/FilamentShieldPlugin.php#L29

@bezhanSalleh Improve isResourcePublished() to allow the resource to be moved to the cluster?