ToggleColumn restore action

Hi, I'm trying to make my togglecolumn restore or softdelete after change, is it possible?
No description
13 Replies
Vp
Vp4mo ago
Do you have any error?
Yosef Bnei Noach
Yes
No description
Vp
Vp4mo ago
can you show your code
Yosef Bnei Noach
You need to see just the Resource or Model too? I just added a ToggleColumn, it seems Filament tries to update "deleted_at" to 0. But I have no idea how to make this toggle restore this row.
Vp
Vp4mo ago
ToggleColumn update boolean (true/false). I don't think you can update another column (not boolean column)
Yosef Bnei Noach
sad 😦
Vp
Vp4mo ago
My suggestions: Make boolean column like is_deleted and update that column using toggleColumn, and you can use ->afterStateUpdated() to update the deleted_at column..
Yosef Bnei Noach
I was thinking to make something like this... It seems is the only one solution
Vp
Vp4mo ago
Something like
Tables\Columns\ToggleColumn::make('is_deleted')
->label('Delete')
->afterStateUpdated(function ($record, $state) {
$record->update([
'deleted_at' => $state ? now() : null,
]);
}),
Tables\Columns\ToggleColumn::make('is_deleted')
->label('Delete')
->afterStateUpdated(function ($record, $state) {
$record->update([
'deleted_at' => $state ? now() : null,
]);
}),
maybe
Yosef Bnei Noach
thank you very much Ill do that @Vp I found a solution through mutators.
Vp
Vp4mo ago
Nice
Want results from more Discord servers?
Add your server
More Posts