F
Filamentβ€’8mo ago
jaocero

Is it possible to use another relationship if the current relationship is null?

As what the title says, I want to use an alternative relationship if the current is null:
Tables\Columns\TextColumn::make('company.name')
->label('Organization')
->placeholder('No organization')
->searchable()
->sortable()
->wrap(),
Tables\Columns\TextColumn::make('company.name')
->label('Organization')
->placeholder('No organization')
->searchable()
->sortable()
->wrap(),
if the company.name is null then i will use company.external.name
Solution:
You could use something like this. ``` ->getStateUsing(function($record){ Return $record->company->name ?? $record->external->name ?? Null; })...
Jump to solution
2 Replies
Solution
dissto
disstoβ€’8mo ago
You could use something like this. ``` ->getStateUsing(function($record){ Return $record->company->name ?? $record->external->name ?? Null; }) Probably want to add additional checks, but you get the gist 😁
jaocero
jaoceroβ€’8mo ago
It worksss thank youuu