F
Filamentβ€’2mo ago
F alko

Format Pivot fields in Relation Manager

This is the table of my RelationManager. I have a many-to-many relation with a view properties on my pivot. I would like to add multiple pivot values together, but can't seem to find a way to do this. Let's say I have a User object with a many-to-many relation with Subscription. This many-to-many has a Pivot model called SubscriptionUser and pivot fields active and expires_at:
public function table(Table $table): Table
{
return $table
->allowDuplicates()
->columns([
Tables\Columns\TextColumn::make('some_pivot_field')
->formatStateUsing(function ($state, $record) {
// Here I would like to access UserRole.
// I want to be able to see every subscription and make the `active` state orange when expires at is within a month.
// This is not my actual use-case.
}),
]);
}
public function table(Table $table): Table
{
return $table
->allowDuplicates()
->columns([
Tables\Columns\TextColumn::make('some_pivot_field')
->formatStateUsing(function ($state, $record) {
// Here I would like to access UserRole.
// I want to be able to see every subscription and make the `active` state orange when expires at is within a month.
// This is not my actual use-case.
}),
]);
}
4 Replies
F alko
F alkoβ€’2mo ago
Anyone? πŸ™‚
F alko
F alkoβ€’2mo ago
Sadly it does not. That works for 1 column, but I want to concat multiple values of the pivot. Anyone?
Wannes
Wannesβ€’2mo ago
You can concatenate the state right? "${$record->pivot->attr}${$record->pivot->attr2} Or create Pivot Model and define an attribute in there. And add ->using(YourPivotModel::class) to your relationship
Want results from more Discord servers?
Add your server