FilamentF
Filament16mo ago
Kuldeep

How can I create a ToggleColumn to change status from the list page

I've tried with multiple solution to add a ToggleColumn to list page but didn't get a proper success for this.

Issues: Into the database side data is updating for the status column but in the list page toggle is not getting proper record and showing only active/inactive as a toggle.

Here is my code, is ther any problem or I'm missing something or else?
ToggleColumn::make('status')
                    ->onColor('success')
                    ->offColor('warning')
                    ->onIcon('heroicon-s-check')
                    ->offIcon('heroicon-s-x-mark')
                    ->label('Status')
                    ->getStateUsing(fn($record): bool => $record->status === 1)
                    ->afterStateUpdated(function ($record, $state, $livewire) {
                        $record->update(['status' => $state ? 1 : 0]);

                        Notification::make()
                            ->title('')
                            ->success()
                            ->body('Status updated successfully!')
                            ->send();

                        $livewire->getTableRecords();
                    }),
Was this page helpful?