editOptionForm with permissions

Hi, I have a select form component which uses a relationship to look at another model. I use editOptionForm to create a modal so that I can edit the selected field. This all works fine. However, I would like the edit button to only show for certain users (which I'll manage with spatie) - but I'm not sure how to make the button show / hide? Any ideas? Thanks
1 Reply
Adam Holmes
Adam HolmesOP7mo ago
Ahhh it looks like you can update the action - which means you can just call all the usual methods i.e. visible
->manageOptionForm(ListItem::getForm())
->createOptionAction(function (Action $action) {
$action->visible(auth()->user()->can('create', ListItem::class));
})
->editOptionAction(function (Action $action, Get $get) {
$action->visible(auth()->user()->can('update', [ListItem::class, ListItem::find($get('team'))]));
})
->manageOptionForm(ListItem::getForm())
->createOptionAction(function (Action $action) {
$action->visible(auth()->user()->can('create', ListItem::class));
})
->editOptionAction(function (Action $action, Get $get) {
$action->visible(auth()->user()->can('update', [ListItem::class, ListItem::find($get('team'))]));
})
Want results from more Discord servers?
Add your server