FilamentF
Filament16mo 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.
                }),
        ]);
}
Was this page helpful?