FilamentF
Filament2y 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
        }
    }),

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
if ($recommendCount >= 15) {
    Notification::make()
        ->title('Error')
        ->warning()
        ->send();

    throw ValidationException::withMessages([]);
}
Was this page helpful?