© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
9 replies
rg.block

Display relationship on table column

I currently have a table with 2 of its columns displaying the name of a city and its state respectively. I would like to be able to combine them into one column, but I have tried several approaches and neither one works as I just get no data on the combined column.

I currently have it in two columns like this:

protected function getTableColumns(): array
    {
        return [
            TextColumn::make('name')->searchable(),
            TextColumn::make('created_at')
                ->label('Date')
                ->date()
                ->sortable(),
            TextColumn::make('city.name')
                ->label('City')
                ->sortable(),
            TextColumn::make('city.state.name')
                ->label('State')
                ->sortable(),
   ];
}
protected function getTableColumns(): array
    {
        return [
            TextColumn::make('name')->searchable(),
            TextColumn::make('created_at')
                ->label('Date')
                ->date()
                ->sortable(),
            TextColumn::make('city.name')
                ->label('City')
                ->sortable(),
            TextColumn::make('city.state.name')
                ->label('State')
                ->sortable(),
   ];
}


The option I tried that to me appeared to be close was using formatStateUsing like this:

TextColumn::make('City, State')
                ->formatStateUsing(function (Package $package) {
                    if ($package->city && $package->city->state) {
                        return "{$package->city->name}, {$package->city->state->name}";
                    }
                    return '';
                }),
TextColumn::make('City, State')
                ->formatStateUsing(function (Package $package) {
                    if ($package->city && $package->city->state) {
                        return "{$package->city->name}, {$package->city->state->name}";
                    }
                    return '';
                }),


But that still did not work. I think I am doing something wrong or maybe missing something.

That is assuming it is possible to display what I need in one column.

Does anyone have a suggestion/fix that can accomplish displaying the city and state under the same column?
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

JSON relationship column in table
FilamentFFilament / ❓┊help
14mo ago
Select Column relationship in Table.
FilamentFFilament / ❓┊help
2y ago
Display count of relationship in table column where pivot value = something
FilamentFFilament / ❓┊help
3y ago
Display Table info with Recursive Relationship
FilamentFFilament / ❓┊help
2y ago