how to globally disable create another ?

how to globally disable all create another ? like in a service provider can you do that?
4 Replies
Jordy
Jordy3w ago
your question is pretty vague ngl.. I think you are looking for the usage of policies, which FIlament automatically enforces https://filamentphp.com/docs/3.x/panels/resources/viewing-records#authorization this goes for pretty much all default filament actions. you will have to enforce it on custom actions/pages yourself
KingStalker
KingStalkerOP3w ago
Thanks for the input! I was hoping there might be a simpler way to globally disable the 'Create Another' button, perhaps through a setting in the panel or a method in a service provider. From what I understand, it seems like I'd need to set:
protected static bool $canCreateAnother = false;
protected static bool $canCreateAnother = false;
on each individual create page. Is that really the only approach, or is there a more global solution, like a method such as $panel->disableCreateAnotherButtonGlobally() that could handle it across all resources?
Jordy
Jordy3w ago
should be gone when the policy returns false when a record exists? else you can set a default in AppServiceProvider like so (works for almost all filament components)
CreateAction::configureUsing(function (CreateAction $action): void {
$action->createAnother(false);
});
CreateAction::configureUsing(function (CreateAction $action): void {
$action->createAnother(false);
});
https://filamentphp.com/docs/3.x/tables/advanced#global-settings this will set a default for all of them across the entire app tho, you can override it when needed now I think about it there might be a way to set it in the panel provider aswell, let me check yep this seems to work aswell in the panel provider:
public function panel(Panel $panel): Panel
{
$panel->configureUsing(function () {
//configure components
});

return $panel...;
}
public function panel(Panel $panel): Panel
{
$panel->configureUsing(function () {
//configure components
});

return $panel...;
}
not sure if thats the intended way to go about it though ( @KingStalker )
KingStalker
KingStalkerOP3w ago
thanks i give it a go when i get back

Did you find this page helpful?