F
Filament7mo ago
Vp

halt table toggle column

How can I halt (not updating DB) toggle column?
Tables\Columns\ToggleColumn::make('recommend')
->beforeStateUpdated(function () {
$recommendCount = Model::where('recommend', true)->count();

if ($recommendCount >= 15) {
// @todo(notification)
return false; // not working
}
}),
Tables\Columns\ToggleColumn::make('recommend')
->beforeStateUpdated(function () {
$recommendCount = Model::where('recommend', true)->count();

if ($recommendCount >= 15) {
// @todo(notification)
return false; // not working
}
}),
In my case, if recommend count is gte = 15, I want to hold that event and shows notification and hold update process, but it still updating, how can I make it "not to update table" Thanks in advance
Solution:
I try like below and it's not updating anymore, so I think this validation error halt the process ```php if ($recommendCount >= 15) { Notification::make() ->title('Error')...
Jump to solution
4 Replies
Dennis Koch
Dennis Koch7mo ago
Not sure whether there is a way to halt it. Maybe just overwrite updateStateUsing() to add your validation. Did you try throwing a validation error from beforeStateUpdated()?
Solution
Vp
Vp7mo ago
I try like below and it's not updating anymore, so I think this validation error halt the process
if ($recommendCount >= 15) {
Notification::make()
->title('Error')
->warning()
->send();

throw ValidationException::withMessages([]);
}
if ($recommendCount >= 15) {
Notification::make()
->title('Error')
->warning()
->send();

throw ValidationException::withMessages([]);
}
Dennis Koch
Dennis Koch7mo ago
So that's working for you?
Vp
Vp7mo ago
Yes, working.. thanks