How to create a dynamic table actions based on record ?

I try to create a dynamic actions in table, but in table actions method i can access the current record
5 Replies
Iranzi Dev
Iranzi Dev5mo ago
What do you mean clearly
Rahman Ramsi
Rahman Ramsi5mo ago
something like this
$table->actions(fn($record) => $record->getFilamentActions())
$table->actions(fn($record) => $record->getFilamentActions())
i want to show an actions based on the record
ChesterS
ChesterS5mo ago
You've got your answer already. Either add the method on the model or create a separate method/helper/class somewhere that accepts the model as an argument and returns the actions eg
public static function getUserActions(User $user) {
if ($user->is_admin) return ...
public static function getUserActions(User $user) {
if ($user->is_admin) return ...
and then do
$table->actions(fn($record) => MyClass::getUserActions($user))
$table->actions(fn($record) => MyClass::getUserActions($user))
Rahman Ramsi
Rahman Ramsi5mo ago
this is not a valid code, actions doesnt accept the closure, only array. Also i want to create an actions based on record on table, not user
awcodes
awcodes5mo ago
I think you might be thinking about this backwards. ->actions() modifier should be an array of possible actions. Then each action has access to the record so you can show and hide them using ->hidden(fn($record) => $record->shouldShowMethod()) on each action.
Want results from more Discord servers?
Add your server
More Posts