Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

wardhache's avatar

Conditionally hide SelectColumn in FilamentPHP table based on email domain

I'm working on a Laravel project using FilamentPHP and need some help conditionally hiding a column in a table.

Here's the relevant code snippet:

public static function table(Table $table): Table
{
    return $table
        ->columns([
            Tables\Columns\TextColumn::make('name')
                ->searchable(),
            Tables\Columns\TextColumn::make('email')
                ->searchable(),
            Tables\Columns\SelectColumn::make('department_id')
                ->label('Department')
                ->options(Department::all()->pluck('name', 'id')),
        ]);
}

The department_id column should only display when the user’s email address does end with "@mycompany.com". If it doesn't, I'd like this column to be hidden for that specific row.

Is there a way to conditionally hide a column based on a record's attribute like this in FilamentPHP?

0 likes
4 replies
jaseofspades88's avatar

Yes, I would conditionally render accordingly using the formatStateUsing method on the column. It works as follows

->formatStateUsing(fn (Model $record) => str($model->email)->endsWith('@mycompany.com') ? ' - ' : $model->email)

Make the necessary internal logic changes that I otherwise cannot guess within your closure. I would be inclined to make it more flexible, however. Accepting multiple domains that you don't wish to display, for example.

wardhache's avatar

@jaseofspades88 Looks like there is no formatStateUsing method:

Tables\Columns\SelectColumn::make('department_id')
                    ->label('Department')
                    ->options(Department::all()->pluck('name', 'id'))
                    ->formatStateUsing(function ($state) {
                        dd($state);
                    })

When I tried the snippet above, I get this error: Method Filament\Tables\Columns\SelectColumn::formatStateUsing does not exist.

Rebwar's avatar
Rebwar
Best Answer
Level 32

@wardhache You cannot conditionally hide or show a table column based on individual records because HTML tables require a consistent structure across all rows. This means every row must display the same set of columns.

However, if your goal is to conditionally hide and disable the department select field for users whose email does not end with @mycompany.com, you can accomplish this by applying tailwind hidden class to the SelectColumn and then conditionally disabling the field.

Tables\Columns\SelectColumn::make('department_id')
    ->label('Department')
    ->options(Department::all()->pluck('name', 'id'))
    ->extraAttributes(fn($record) => [
        'class' => Str::endsWith($record->email, '@mycompany.com') ? '' : 'hidden'
    ])
    ->disabled(fn($record) => !Str::endsWith($record->email, '@mycompany.com'));

Additionally, you can conditionally load select options:

->options(function ($record): array {
    if (Str::endsWith($record->email, '@mycompany.com')) {
        // return departments array
    }
    // Otherwise get an empty array
    return [];
})
1 like
wardhache's avatar

Thanks for the clarification, Rebwar!

Please or to participate in this conversation.