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')
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();
}
public function userHasDepartments(): BelongsToMany
{
return $this->belongsToMany(User::class, 'user_has_department')
->withPivot(['is_active'])
->withTimestamps();
}
Solution:
i found a solution: ```php Tables\Columns\ToggleColumn::make('is_active') ->getStateUsing(fn ($record) => $record->pivot->is_active) <--- add this ->sortable()...
Jump to solution
2 Replies
Solution
Rolland
Rolland3mo ago
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'),
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'),
Want results from more Discord servers?
Add your server