© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
3 replies
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
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
NA
when not filled in in the database
Solution
Take a look at : https://filamentphp.com/docs/3.x/tables/columns/getting-started#adding-placeholder-text-if-a-column-is-empty
Getting started - Table Builder - Filament
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Repeater - formatStateUsing
FilamentFFilament / ❓┊help
3y ago
Copyable value with formatStateUsing function
FilamentFFilament / ❓┊help
3y ago
Updating TextEntry using formatStateUsing
FilamentFFilament / ❓┊help
6mo ago
formatStateUsing not being called
FilamentFFilament / ❓┊help
16mo ago