FilamentF
Filament15mo ago
Rolland

Interact with Pivot attributes in Relation Manager

Tables\Columns\ToggleColumn::make('is_active')
                    ->label(__('department.attributes.is_active'))
                    ->onIcon('heroicon-o-eye')
                    ->offIcon('heroicon-o-eye-slash')


I wanted to update the is_active but it is not updating. not sure what i did wrong here.

Department model:
public function userHasDepartments(): BelongsToMany
    {
        return $this->belongsToMany(User::class, 'user_has_department')
            ->withPivot(['is_active'])
            ->withTimestamps();
    }
Solution
i found a solution:
Tables\Columns\ToggleColumn::make('is_active')
    ->getStateUsing(fn ($record) => $record->pivot->is_active) <--- add this
    ->sortable()
    ->onIcon('heroicon-o-eye')
    ->offIcon('heroicon-o-eye-slash')
    ->label('Status'),           
Was this page helpful?