hi i'm getting this setup and i want to add a new menu element but only show it to certain people? i can add elements to the array in menu.php so they show up, but i wanted to do something like
if(auth()->id == 123){
"special hidden menu item"
}
but this fails because auth is not available and shows this error:
Illuminate \ Contracts \ Container \ BindingResolutionException
Target class [auth] does not exist.
any advice please?
Hi
In Laravel, we have implemented the menu permission using spatie/laravel-permission plugin.
You can check the menu filter code here.app/Core/Adapters/Menu.php
Add permission
or role
in the menu config. For example;
array(
"title" => "Overview",
"path" => "documentation/getting-started/overview",
"role" => ["admin"],
),
$role = Role::create(["name" => "admin"]);
auth()->user->assignRole("admin");
great that looks exactly right thank you!
No problem. Glad it helps you.
Thanks