Roy
Roy
FFilament
Created by Roy on 9/26/2024 in #❓┊help
Revert togglecolumn $state if condition unsatisfied.
I have togglecolumn on table. when
ToggleColumn::make( 'confirmed' )
->label( 'Confirmed' )
->updateStateUsing( function ($record, $state): bool {
$user = auth()->user();

if ($user->hasRole( 'admin' )) {
return $state; // Confirm toggle on success
} else {
throw ValidationException::withMessages( [] );
}

} ),
ToggleColumn::make( 'confirmed' )
->label( 'Confirmed' )
->updateStateUsing( function ($record, $state): bool {
$user = auth()->user();

if ($user->hasRole( 'admin' )) {
return $state; // Confirm toggle on success
} else {
throw ValidationException::withMessages( [] );
}

} ),
if the togglecolumn is currently false, when toggle from false to true, if the condition didn't meet, the toggle stay at false. the problem is if the togglecolumn is currently true, when toggle from true to false, if the condition didnt meet, the toggle will still move to false. if refresh the page, the toggle will show true again. I supposed it should stay at true instead of going to false? Any hints or guidance would be greatly appreciated!
15 replies