![logo light](https://filamentglow.com/images/head-glow.webp)
Implementing Authorization for Creating Options
- Published: 15 Apr 2024 Updated: 04 May 2024
How to Apply Authorization on Create Option Action for Select Field
![Implementing Authorization for Creating Options](https://filamentglow.com/storage/media/2e2bad5c-6e96-4b63-8da4-42415ffb0fc5.png)
When using createOptionForm
for a select menu, you can customize the add action (+). One important thing is to add authorization to that action, for example, from a policy.
This will hide the add button next to the select menu when the user is not authorized to create, and the same goes for the edit action.
1Select::make('category_id') 2 //... 3 ->relationship(...) 4 ->createOptionForm(...) 5 ->createOptionAction( 6 fn(Action $action) => $action->hidden( 7 auth()->user()->cannot( 8 'create', 9 Category::class10 )11 )12 ),
![logo light](https://filamentglow.com/images/head-glow.webp)
Related Tricks:
Custom copy action, click the icon to copy the content
how to use a resource with multiple models
Let Users to Select All Options with a Simple Hint Action
Translating components can often be a repetitive task, Fortunately, there's a neat trick to automate this process, making your components instantly translatable.
get translatable attribute in a relationships