Table Toggle Column Issue in v3.2.131

In the provided video, the toggle column not works correctly in simple resources like Processing Fee Categories but in database value changed In normal resource with view page like Branches toggle column works correctly In Previous Version 3.2.110, their is no issues how to fix this in latest version
Solution:
Do both models cast the same?
Jump to solution
9 Replies
toeknee
toeknee2mo ago
It sounds like you have a different function for the status column and one is returning a false so the status isn't showing updated
Parthiban N
Parthiban NOP2mo ago
<?php namespace App\Concerns\Component; use App\Enums\StatusEnum; use Filament\Tables\Columns; use Filament\Forms\Components as FormComponents; use Filament\Infolists\Components as InfolistComponents; trait Status { protected static function statusToggleFormComponent() : FormComponents\Field { return FormComponents\Toggle::make('status') ->label(('general.form_fields.status')) ->onColor('success') ->offColor('danger') ->default(true); } protected static function statusBadgeColumnComponent() : Columns\Column { return Columns\BadgeColumn::make('status') ->sortable(false); } protected static function statusToggleColumnComponent(bool | \Closure $visibleCondition = true) : Columns\Column { return Columns\ToggleColumn::make('status') ->sortable(false) ->onColor('success') ->offColor('danger') ->visible($visibleCondition) ->toggleable(isToggledHiddenByDefault: true) ->afterStateUpdated(fn() => \Helpers::toast( title: ('general.success_message.status_update'), color: 'success' )); } protected static function statusBadgeInfolistComponent() : InfolistComponents\Entry { return InfolistComponents\TextEntry::make('status') ->label(__('general.info_fields.status')) ->badge() ->color(fn(int $state): string => StatusEnum::tryFrom($state)->getColor()) ->formatStateUsing(fn(int $state): string => StatusEnum::tryFrom($state)->getLabel()); } } i am using trait's statusToggleColumnComponent method wherever i need status toggle column i am using this same trait in version 3.2.110 it works
Solution
toeknee
toeknee2mo ago
Do both models cast the same?
Parthiban N
Parthiban NOP2mo ago
No, Thanks for your help i forgot that now i fixed it
Parthiban N
Parthiban NOP2mo ago
i have a doubt i'm created the status column as boolean type in mysql and cast as StatusEnum in model that will not work how to do that? @toeknee
toeknee
toeknee2mo ago
It's expected to be a status boolean, what does StatusEnum return? if it's boolean, then it's fine... But toggleColumn expects boolean.
Parthiban N
Parthiban NOP2mo ago
<?php namespace App\Enums; use Filament\Support\Contracts\HasColor; use Filament\Support\Contracts\HasLabel; enum StatusEnum: int implements HasLabel, HasColor { case Enable = 1; case Disable = 0; public function getLabel(): ?string { return match ($this) { self::Enable => 'Enabled', self::Disable => 'Disabled', }; } public function getColor(): string | array | null { return match ($this) { self::Enable => 'success', self::Disable => 'danger', }; } public function getAllValues() : array { return array_column(self::cases(), 'value'); } } i am using this enum for the casting but it doesn't works
toeknee
toeknee2mo ago
No because you are casing it as 1/0 not true/false review how the laravel boolean cast works and implement that
Parthiban N
Parthiban NOP2mo ago
Ok Thanks

Did you find this page helpful?