- Using Gate facade:
use Illuminate\Support\Facades\Gate;
use MoonShine\Laravel\Enums\Ability;
protected function menu(): array
{
return [
MenuItem::make('Roles', MoonShineUserRoleResource::class)
->canSee(fn() => Gate::check(Ability::VIEW_ANY, MoonshineUserRole::class)),
];
}
use Illuminate\Support\Facades\Gate;
use MoonShine\Laravel\Enums\Ability;
protected function menu(): array
{
return [
MenuItem::make('Roles', MoonShineUserRoleResource::class)
->canSee(fn() => Gate::check(Ability::VIEW_ANY, MoonshineUserRole::class)),
];
}
- Using resource:
use MoonShine\Laravel\Enums\Ability;
protected function menu(): array
{
return [
MenuItem::make('Roles', MoonShineUserRoleResource::class)
->canSee(fn(MenuItem $item) => $item->getFiller()->can(Ability::VIEW_ANY)),
];
}
use MoonShine\Laravel\Enums\Ability;
protected function menu(): array
{
return [
MenuItem::make('Roles', MoonShineUserRoleResource::class)
->canSee(fn(MenuItem $item) => $item->getFiller()->can(Ability::VIEW_ANY)),
];
}
- Without Policy:
protected function menu(): array
{
$menu = [
MenuItem::make('Articles', ArticleResource::class),
];
if (request()->user()->isSuperUser()) {
$menu[] = MenuItem::make('Admins', MoonShineUserResource::class);
}
return $menu;
}
protected function menu(): array
{
$menu = [
MenuItem::make('Articles', ArticleResource::class),
];
if (request()->user()->isSuperUser()) {
$menu[] = MenuItem::make('Admins', MoonShineUserResource::class);
}
return $menu;
}