Custom Table Action

Hi team I am adding a custom table action that can active and de-active a community this is my code but it seems not to work as expected Action::make("de-activate") ->action( fn (Community $record) => $record->update([ 'is_active' => true ]) )
->color('danger')
20 Replies
toeknee
toeknee13mo ago
is_active fillable on the modal.
codeartisan
codeartisanOP13mo ago
Yeah it is protected $fillable = [ 'name', 'description', 'is_active', 'account_name', 'account_number', 'account_balance', 'leader_id' ]; And also how do I make that action dynamic as well
ashar
ashar13mo ago
what it shows ?? do it show some sort of error on anything ?
einnlleinhatt_
einnlleinhatt_13mo ago
My bad you need to active and deactivate
ashar
ashar13mo ago
no in that case it would be de_Active = true i gues
codeartisan
codeartisanOP13mo ago
no the field is called is_active Yeah it works but I need to make it dynamic and also show a success message
einnlleinhatt_
einnlleinhatt_13mo ago
Action::make("Buttong")
->action(
function (Community $record) {
$record->update([
'is_active' => !$record->is_active
]);
}
)
->color(function (Community $record) {
return $record->is_active ? 'danger' : 'success';
});
Action::make("Buttong")
->action(
function (Community $record) {
$record->update([
'is_active' => !$record->is_active
]);
}
)
->color(function (Community $record) {
return $record->is_active ? 'danger' : 'success';
});
codeartisan
codeartisanOP13mo ago
How best can I do that
ashar
ashar13mo ago
how are you expecting it to work ?? @codeartisan didnt get what you actually want :/ is it working , not wotking or working but not upto your expectations ? be very clear with what you asking for 🙂
codeartisan
codeartisanOP13mo ago
As per now it works the value is actually being changed I just need to make the button name dynamic and show a success message for either actiavted or de-activated thank you very much everyone
toeknee
toeknee13mo ago
You can also trigger a Filamentphp Notification
ChesterS
ChesterS13mo ago
Can you try this and see if it works?
Action::make("deActivate")
->action(
function (Community $record) {
$record->is_active = false;
$record->save();
}
)
Action::make("deActivate")
->action(
function (Community $record) {
$record->is_active = false;
$record->save();
}
)
codeartisan
codeartisanOP13mo ago
works fine as well
ChesterS
ChesterS13mo ago
Oh shit nvm didn't see that the original works as well, my bad.
codeartisan
codeartisanOP13mo ago
Guys am left with making the button name dynamic Action::make("Buttong") ->action( function (Community $record) { $record->update([ 'is_active' => !$record->is_active ]); Notification::make() ->title('Community status updated') ->success() ->send(); } ) ->color(function (Community $record) { return $record->is_active ? 'danger' : 'success'; }) anyone with an idea about making the button name dynamic
einnlleinhatt_
einnlleinhatt_13mo ago
Action::make(function (Community $record) {
return $record->is_active ? 'Deactivate' : 'Activate';
})
->action(function (Community $record) {
$record->update([
'is_active' => !$record->is_active
]);
Notification::make()
->title('Community status updated')
->success()
->send();
})
->color(function (Community $record) {
return $record->is_active ? 'danger' : 'success';
});
Action::make(function (Community $record) {
return $record->is_active ? 'Deactivate' : 'Activate';
})
->action(function (Community $record) {
$record->update([
'is_active' => !$record->is_active
]);
Notification::make()
->title('Community status updated')
->success()
->send();
})
->color(function (Community $record) {
return $record->is_active ? 'danger' : 'success';
});
Something like this?
codeartisan
codeartisanOP13mo ago
my bad actually anything in the table can take in a function thank you guys For some reason that does not work the make function expects a string not a function
einnlleinhatt_
einnlleinhatt_13mo ago
Ohh maybe you can warp it inside label()?
codeartisan
codeartisanOP13mo ago
incase anyone needs the same functionality it works fine Action::make("Activation") ->action( function (Community $record) { $record->update([ 'is_active' => !$record->is_active ]); Notification::make() ->title('Community status updated') ->success() ->send(); } ) ->color(function (Community $record) { return $record->is_active ? 'danger' : 'success'; }) ->label(function (Community $record) { return $record->is_active ? 'Deactivate' : 'Activate'; }), thank you very much everyone
3rgo
3rgo13mo ago
Why didn't you use the ToggleColumn ? https://filamentphp.com/docs/3.x/tables/columns/toggle You can use the lifecycle hook to display the notification
Want results from more Discord servers?
Add your server