bezhanSalleh / filament-shield

The easiest and most intuitive way to add access management to your Filament Admin Resources, Pages & Widgets through `spatie/laravel-permission`
MIT License
1.35k stars 166 forks source link

How to transfer RoleResource.php in Clusters? #360

Closed free-storage closed 3 months ago

free-storage commented 3 months ago

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.

bezhanSalleh commented 3 months ago

Just register your cluster class in the shield config.

free-storage commented 3 months ago

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.

bezhanSalleh commented 3 months ago

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

free-storage commented 3 months ago

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

free-storage commented 3 months ago

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