You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
when i make the action column hidden the table layout is changing. I need to make the column visible/hidden with roles and i ma using spatie for it.
This is my code
public function columns(): array {
// Determine the user's roles
$userRoles = auth()->user()->roles;
// Define the columns array
$columns = [
Column::make('ID', 'id')
->sortable()
->searchable(),
Column::make('Name', 'user_name')
->sortable()
->searchable(),
Column::make('Email', 'user_email')
->sortable()
->searchable(),
Column::make('Gender', 'gender')
->sortable()
->searchable(),
Column::make('Department', 'department')
->sortable()
->searchable(),
Column::make('Designation', 'designation')
->sortable()
->searchable(),
Column::make('Primary Contact', 'primary_contact')
->sortable()
->searchable(),
Column::make('Secondary Contact', 'secondary_contact')
->sortable()
->searchable(),
Column::make('Address', 'address')
->sortable()
->searchable(),
];
// Check if the user has the role that allows them to see the "Role" column
$canSeeRoleColumn = $userRoles->whereIn('name', ['Superadmin', 'Admin'])->isNotEmpty();
// Check if the user has the role that allows them to see the "Action" column
$canSeeActionColumn = $userRoles->whereIn('name', ['Superadmin', 'Admin'])->isNotEmpty();
$hideActionColumn = $userRoles->whereIn('name', ['User'])->isNotEmpty();
// If the user has the role, add the "Action" column to the columns array
if ($canSeeActionColumn) {
$columns[] = Column::action('Action');
}
// If the user has the role, add the "Role" column to the columns array
if ($hideActionColumn) {
$columns[] = Column::action('Action')
->hidden();
}
// If the user has the role, add the "Role" column to the columns array
if ($canSeeRoleColumn) {
$columns[] = Column::make('Role', 'user_role')
->sortable()
->searchable();
}
return $columns;
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
when i make the action column hidden the table layout is changing. I need to make the column visible/hidden with roles and i ma using spatie for it.


This is my code
public function columns(): array {
// Determine the user's roles
$userRoles = auth()->user()->roles;
Beta Was this translation helpful? Give feedback.
All reactions