F
Filament2mo ago
Akimbo

No way to add sideeffects to ToggleColumn?

I am making an admin panel to interact with another API. When the user toggles a ToggleColumn switch, I want to conditionally allow the state change depending on the API. Unfortunately I can't get any kind of conditional state change on ToggleColumn. I have tried updating the event after state is updated.
Tables\Columns\ToggleColumn::make('live')
->sortable()
->afterStateUpdated(function (Event $event) {
if ($event->live == '1') {
$event->update(['live' => '0']);
$event->save();
}
}),
Tables\Columns\ToggleColumn::make('live')
->sortable()
->afterStateUpdated(function (Event $event) {
if ($event->live == '1') {
$event->update(['live' => '0']);
$event->save();
}
}),
I have tried updateStateUsing, which doesn't seem to update the state as far as I can tell.
Tables\Columns\ToggleColumn::make('live')
->updateStateUsing(function (Event $event) {
$event->update(['live' => true]);
})
Tables\Columns\ToggleColumn::make('live')
->updateStateUsing(function (Event $event) {
$event->update(['live' => true]);
})
Solution:
Sounds like an issue with your model then. Not Filament. Is the field fillable?
Jump to solution
6 Replies
Akimbo
AkimboOP2mo ago
Bump
Dennis Koch
Dennis Koch2mo ago
I have tried updateStateUsing, which doesn't seem to update the state as far as I can tell.
So your event is not $live = true aftetr this? Is the callback called?
Akimbo
AkimboOP2mo ago
It's definitely called, but it's not $live = true after.
Solution
Dennis Koch
Dennis Koch2mo ago
Sounds like an issue with your model then. Not Filament. Is the field fillable?
Akimbo
AkimboOP2mo ago
No! Thank you, thought that would error out.
Dennis Koch
Dennis Koch2mo ago
I think Model::preventSilentlyDiscardingAttributes() in a ServiceProvider should do that

Did you find this page helpful?