TextColumn relationship unique values

I have a text column that contains country names through a relationship. How do I get this to only display unique names?
Tables\Columns\TextColumn::make('countries.name'),
Tables\Columns\TextColumn::make('countries.name'),
3 Replies
toeknee
toeknee13mo ago
I am not sure I follow? If it is a relationship it will show what's in the relationship. The countries should only have unique names within it?
OnlyTieBowline
OnlyTieBowlineOP13mo ago
To clarify, countries is a has many through (cities) relationship. So if a title has two USA cities, USA is showing up twice in the countries column.
johnnie_littleshoes
I do it like this, but probably it's not the "correct" way, though it works
->state(
fn($record) => $record->countries->map(fn($country) => $country->name)->unique()
)
->state(
fn($record) => $record->countries->map(fn($country) => $country->name)->unique()
)
Want results from more Discord servers?
Add your server