F
Filamentβ€’16mo ago
Scott

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)
Solution:
Yes add ->visibile(fn($record) => auth()->user()->can('create Site'))
Jump to solution
10 Replies
Solution
toeknee
toekneeβ€’16mo ago
Yes add ->visibile(fn($record) => auth()->user()->can('create Site'))
toeknee
toekneeβ€’16mo ago
to the create action in the listpage
Scott
ScottOPβ€’16mo ago
oh man, I love Filament
toeknee
toekneeβ€’16mo ago
But if you are doing it for permission reasons, you should smash out polices instead πŸ˜‰
Scott
ScottOPβ€’16mo ago
only started learning filament yesterday, permissions is further down my todo list πŸ˜…
toeknee
toekneeβ€’16mo ago
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.
Scott
ScottOPβ€’16mo ago
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'),
toeknee
toekneeβ€’16mo ago
Good stuff
hashim199
hashim199β€’8mo ago
where you put this code to get a new button Actions\Action::make('delete') ->color('danger'),
toeknee
toekneeβ€’8mo ago
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
Want results from more Discord servers?
Add your server