© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
11 replies
BuggerSee

Display value of Pivot Table

Hello,
I'm currently looking for a better and more performant solution to display a pivot table attribute in my relationManager.

It is working right now and using formatStateUsing() but it is doing a lot of DB queries as you might see i use the SponsorType::find() function.


SponsorsRelationManager.php
public static function table(Table $table): Table
    {
        return $table
            ->columns([
                ImageColumn::make('logo_url')
                    ->label('Logo')
                    ->circular()
                ,
                TextColumn::make('name')
                    ->searchable()
                    ->sortable(),
                TextColumn::make('country')
                    ->searchable()
                    ->sortable(),
                TextColumn::make('sponsor_type_id')
                    ->label('Type')
                    // Show the name of the sponsor type instead of the ID
                    ->formatStateUsing(function (string $state) {
                        return SponsorType::find($state)->name;
                    })
                    ->searchable()
                    ->sortable(),
            ])
            ->filters([
                //
            ])
            ->headerActions([
                Tables\Actions\CreateAction::make(),
            ])
            ->actions([
                Tables\Actions\EditAction::make(),
                Tables\Actions\DeleteAction::make(),
            ])
            ->bulkActions([
                Tables\Actions\DeleteBulkAction::make(),
            ]);
    }
public static function table(Table $table): Table
    {
        return $table
            ->columns([
                ImageColumn::make('logo_url')
                    ->label('Logo')
                    ->circular()
                ,
                TextColumn::make('name')
                    ->searchable()
                    ->sortable(),
                TextColumn::make('country')
                    ->searchable()
                    ->sortable(),
                TextColumn::make('sponsor_type_id')
                    ->label('Type')
                    // Show the name of the sponsor type instead of the ID
                    ->formatStateUsing(function (string $state) {
                        return SponsorType::find($state)->name;
                    })
                    ->searchable()
                    ->sortable(),
            ])
            ->filters([
                //
            ])
            ->headerActions([
                Tables\Actions\CreateAction::make(),
            ])
            ->actions([
                Tables\Actions\EditAction::make(),
                Tables\Actions\DeleteAction::make(),
            ])
            ->bulkActions([
                Tables\Actions\DeleteBulkAction::make(),
            ]);
    }
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Display count of relationship in table column where pivot value = something
FilamentFFilament / ❓┊help
3y ago
Pivot of pivot
FilamentFFilament / ❓┊help
2y ago
Cannot show value from pivot table in table builder column?
FilamentFFilament / ❓┊help
3y ago
Editing pivot table relating 3 tables
FilamentFFilament / ❓┊help
3y ago