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')
->color('danger')
20 Replies
is_active fillable on the modal.
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
what it shows ?? do it show some sort of error on anything ?
My bad you need to active and deactivate
no in that case it would be de_Active = true
i gues
no the field is called is_active
Yeah it works but I need to make it dynamic and also show a success message
How best can I do that
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 🙂
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
You can also trigger a Filamentphp Notification
Can you try this and see if it works?
works fine as well
Oh shit nvm didn't see that the original works as well, my bad.
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
Something like this?
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
Ohh maybe you can warp it inside label()?
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
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