Is there a way to conditionally disable the new post button?
Hi guys,
Thank you for all your help today! I was wondering if there's a way to conditionally disable the "New" button on a resource?
I only want the "New" button to be enabled once a user has completed a number of setup steps.
And on a similar vein, I want to add another button next to the "New site" button that says "Authorise Airtable" (this is the step they need to take before being able to add a new site)
10 Replies
Solution
Yes add ->visibile(fn($record) => auth()->user()->can('create Site'))
to the create action in the listpage
oh man, I love Filament
But if you are doing it for permission reasons, you should smash out polices instead π
only started learning filament yesterday, permissions is further down my todo list π
So don't do the above if it's for permissions ;-). If you implement lavael policies on the models we use them. And the likes of shield can get you up and running on that in a few minutes and you then have granular permissions on all your resources, widgets and pages.
whilst generating all your policies for you.
Nice, thank you - i'll dig deeper.
Sorry, one last thing as I can't seem to find it in the docs. How would I add a new button next to the Create button?
nevermind
figured it out!
Actions\Action::make('delete')
->color('danger'),
Good stuff
where you put this code to get a new button
Actions\Action::make('delete')
->color('danger'),
It depends which action you are extending and where you want the button, if it's in the page then in the page resource if it's in the tables in the table resource