© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
5 replies
Mikail

->updateStateUsing on ToggleColumn

There must be an active record no matter what in the resource which works fine in the database with a modification using ->updateStateUsing as shown in code below. The only issue is that toggle button won't go back to 'on' in the view until browser refresh.
Anything I could do?

  ToggleColumn::make('status')
                    ->label('Active')
                    ->updateStateUsing(function ($record, $state) {
                        if (!$state) {
                            $schoolId = Filament::getTenant()->id;
                            $hasOtherActive = $record::where('id', '!=', $record->id)
                                ->where('school_id', $schoolId)
                                ->where('status', true)
                                ->exists();

                            if (!$hasOtherActive) {
                                Notification::make()
                                    ->danger()
                                    ->title('Update Failed')
                                    ->body('There must be at least one active session.')
                                    ->send();
                                return $state = true;
                            }
                        } else {
                            return $record->update(['status' => $state]);
                        }
                    })
  ToggleColumn::make('status')
                    ->label('Active')
                    ->updateStateUsing(function ($record, $state) {
                        if (!$state) {
                            $schoolId = Filament::getTenant()->id;
                            $hasOtherActive = $record::where('id', '!=', $record->id)
                                ->where('school_id', $schoolId)
                                ->where('status', true)
                                ->exists();

                            if (!$hasOtherActive) {
                                Notification::make()
                                    ->danger()
                                    ->title('Update Failed')
                                    ->body('There must be at least one active session.')
                                    ->send();
                                return $state = true;
                            }
                        } else {
                            return $record->update(['status' => $state]);
                        }
                    })
Solution
Solved it with:

->disabled(fn ($record) => $record->status)
->disabled(fn ($record) => $record->status)


this will disable the toggle button it altogether if status is set active.
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

ToggleColumn
FilamentFFilament / ❓┊help
10mo ago
ToggleColumn Pivot
FilamentFFilament / ❓┊help
3y ago
ToggleColumn Action
FilamentFFilament / ❓┊help
3y ago
ToggleColumn Issues
FilamentFFilament / ❓┊help
3y ago