Admin Menu
Hello Bobby
How can I apply roles and permission when using voyager's menu? If I go to Wave Admin, will show Admin's menu items based on roles and privileges (like it should be), but when I use the following code
{{ menu('admin','themes.tailwind.menus.partials.vertical-system-settings')}}
and iterate to extract $items, I get all admin menu items. So, How can I get only the items that the user should only be able to work with based on role and privileges? (No, I don't want to create another menu. I want to be able to use voyager's role and permission too.)
Thank you in advance
Hi there!
That is a good point, I had to dig into the code myself, and as far as I can see we are using the display method from the Voyager Menu model itself defined here:
As that is coming from the upstream package, you can't edit the logic in there directly, but what you could do is create a new custom helper function by defining it in the wave/src/Helpers/globals.php
file.
In there you could re-use some of the logic defined in the Voyager Menu model and create a custom function that matches your needs.
What you would need is to get the display
method from that Voyager Menu model, and update the logic at line 76 so that the processItems
method is used for other menus rather than just the admin menu.
Hope that this helps and let me know how it goes!
















Yes! It worked.
Thank you Bobby!!!
















No problem at all! Happy to hear that you've got it all working!
Hey,
I believe that, as you are no longer in the class itself, you need to change the static
keyword with the Menu class itself, eg \TCG\Voyager\Models\Menu::
rather than static::
.
Here is some nice information regarding the Scope Resolution Operator in general:
Let me know how it goes!
















I figured it was something like that, but didn't know how to fix it. Thank you Bobby for once again helping me out! It worked.
















No problem at all! Happy to hear that it is working now!