F
Filament10mo ago
Wim

formatStateUsing with condition

I have a table with users. Some users are individuals, others are organizations (db field 'organization' is either true or false). For the organizations I have a field 'organization_name' which is null for individuals. I want to display a table with users. For the organization name is have the following:
Tables\Columns\TextColumn::make('organization_name')
->formatStateUsing(
function ($state, User $user) {
if ($user->organization_name != NULL) {
return $user->organization_name . 'test';
} else {
return 'NA';
}
})
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('organization_name')
->formatStateUsing(
function ($state, User $user) {
if ($user->organization_name != NULL) {
return $user->organization_name . 'test';
} else {
return 'NA';
}
})
->searchable()
->sortable(),
The idea is to display NA in the table where the organization_name is null. However it does only display the organization_name (when filled in in the database) but it does not display the NA when not filled in in the database
2 Replies
Wim
WimOP10mo ago
Oops sorry, I have overlooked the placeholder functionality. My bad!
Want results from more Discord servers?
Add your server