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

Resoures in the sub folders accessable by everyone

wikihadi opened this issue · comments

Resoures in the sub folders accessable by everyone
Screenshot 2024-05-30 010932
داشبوردا

I agree, it's a nice Filament feature to have possibility to use sub folders for Models / Resources, but they won't work with Filament Shield when using subfolders... Any idea how to fix this ? thks

I also agree with you in filament docus they mentionds for subdirectories path used AuthServiceProvider but in laravel 11 there's not AuthServiceProvider class.
Screenshot 2024-06-13 at 1 13 17 AM

Hi
According to the changes of Laravel 11 (https://laravel.com/docs/11.x/authorization#manually-registering-policies) and also the documentation of this package (https://github.com/bezhanSalleh/filament-shield?tab=readme-ov-file#custom-folder-structure-for-models-or-third-party-plugins)
, to fix the problem:
Should manually register policies and their corresponding models within the boot method of your application's AppServiceProvider:

use App\Models\Order;
use App\Policies\OrderPolicy;
use Illuminate\Support\Facades\Gate;
 
/**
 * Bootstrap any application services.
 */
public function boot(): void
{
    Gate::policy(Order::class, OrderPolicy::class);
}