Block DetachAction on some list items

Is there a way to block certain users from detaching certain records from a model? Like not being able to detach users that are higher ranked than them, or specific to my example, detaching records that were attached from an administrative tenant.
Solution:
->actions([
Tables\Actions\DetachAction::make()
->visible(fn (ButtonGroup $record): bool => $record->agency->name !== "ADMINISTRATION"),
])
->actions([
Tables\Actions\DetachAction::make()
->visible(fn (ButtonGroup $record): bool => $record->agency->name !== "ADMINISTRATION"),
])
...
Jump to solution
2 Replies
MarconiMamba
MarconiMambaOP14mo ago
I am successfully using
->checkIfRecordIsSelectableUsing(fn (Model $record): bool => $record->agency->name !== "ADMINISTRATION")
->checkIfRecordIsSelectableUsing(fn (Model $record): bool => $record->agency->name !== "ADMINISTRATION")
to block bulk selection of the item, but I still have the detach button in the line. I was overthinking it. It's literally the same fn in the ->visible function.
Solution
MarconiMamba
MarconiMamba14mo ago
->actions([
Tables\Actions\DetachAction::make()
->visible(fn (ButtonGroup $record): bool => $record->agency->name !== "ADMINISTRATION"),
])
->actions([
Tables\Actions\DetachAction::make()
->visible(fn (ButtonGroup $record): bool => $record->agency->name !== "ADMINISTRATION"),
])
Want results from more Discord servers?
Add your server