Joe IW
Joe IW
FFilament
Created by hxn on 10/14/2023 in #❓┊help
conditional table column
I had a similar use case where I only wanted to display a column for super_admin users, and hide it for ordinary users. I simply stored the columns in an array variable, then conditionally appended to the array if the user was super_admin.
$columns = []; // define columns
if ($user->hasRole('super_admin')) {
array_push($columns, Tables\Columns\TextColumn::make('admin_only_column'));
}

return $table
->columns($columns);
$columns = []; // define columns
if ($user->hasRole('super_admin')) {
array_push($columns, Tables\Columns\TextColumn::make('admin_only_column'));
}

return $table
->columns($columns);
Hope that helps someone.
10 replies