Groups, items, badges and appends are visible by default. Hide them with a boolean:
$item->authorize(auth()->user()?->can('viewAny', User::class) ?? false);
Or with a permission name, checked by the configured driver:
$group->item('Roles', function (Item $item) {
$item->route('admin.roles.index');
$item->authorizePermission('roles.view');
});
Children of a hidden item or group are hidden too.
Set the driver in config/sidebar.php:
'permissions' => [
'driver' => 'spatie',
'resolver' => null,
],
| Driver | Checks |
|---|---|
spatie |
$user->can($permission) on the authenticated user. Works with spatie/laravel-permission and with any Laravel Gate or policy. Guests are denied. |
sentinel |
hasAccess($permission) on the Sentinel user. Requires cartalyst/sentinel. |
none |
Denies every permission name. authorize() with booleans still works. |
For any other system, see Custom permission resolver.