F
Filament17mo ago
xy

Separate policies for different panels

Is there a way to separate policies for each panel? /App/Policies/Customer /App/Policies/Admin With nova i was able to do this in the boot method of AuthServiceProvider using Nova::serving.
2 Replies
Patrick Boivin
Patrick Boivin17mo ago
I'm not sure, but have you tried registering the policies manually from the register() method of a Panel?
Saade
Saade17mo ago
Yes, you can override the default policy name guessing algo and build your own
// AuthServiceProvider

public function boot()
{
Gate::guessPolicyNamesUsing(function ($modelClass) {
return str($modelClass)
->replace(
search: 'App\Models',
replace: 'App\Policies\\' . str(filament()->getCurrentPanel()->getId())->studly()
)
->append('Policy')
->toString();
});
}
// AuthServiceProvider

public function boot()
{
Gate::guessPolicyNamesUsing(function ($modelClass) {
return str($modelClass)
->replace(
search: 'App\Models',
replace: 'App\Policies\\' . str(filament()->getCurrentPanel()->getId())->studly()
)
->append('Policy')
->toString();
});
}
this will scope each model to its own policy based on the current tenant
Want results from more Discord servers?
Add your server