Updating a date with a Table Toggle.

Hi, I have a dateTime filed called archived_on. I'd like to edit this column using a toggle field in a table. Specifically, when the toggle is switched to "off", I want the date field to be set to null, when the toggle is switched to "on", I want the field to be set to now(). How can I go about this?
Solution:
``` ToggleColumn::make('archived_on') ->label('Archived') ->updateStateUsing(function ($state, $record) { $record->archived_on = $state...
Jump to solution
2 Replies
BuddhaNature
BuddhaNature9mo ago
I figured it out with some creative Googling:
Solution
BuddhaNature
BuddhaNature9mo ago
ToggleColumn::make('archived_on')
->label('Archived')
->updateStateUsing(function ($state, $record) {
$record->archived_on = $state
? now()
: null;
$record->save();

return $state;
}),
ToggleColumn::make('archived_on')
->label('Archived')
->updateStateUsing(function ($state, $record) {
$record->archived_on = $state
? now()
: null;
$record->save();

return $state;
}),
Want results from more Discord servers?
Add your server
More Posts