@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 [];
})