PLATFORM
  • Tails

    Create websites with TailwindCSS

  • Blocks

    Design blocks for your website

  • Wave

    Start building the next great SAAS

  • Pines

    Alpine & Tailwind UI Library

  • Auth

    Plug'n Play Authentication for Laravel

  • Designer comingsoon

    Create website designs with AI

  • DevBlog comingsoon

    Blog platform for developers

  • Static

    Build a simple static website

  • SaaS Adventure

    21-day program to build a SAAS

Question By
Solved
Solved
cyberekklesia

Nov 11th, 2022 06:26 PM

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

bobbyiliev

Nov 12th, 2022 11:02 PM

Best Answer

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:

Menu.php#L76-L78

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!

Report
1
cyberekklesia

Nov 13th, 2022 03:32 PM

Yes! It worked.

Thank you Bobby!!!

Report
1
bobbyiliev

Nov 14th, 2022 01:21 AM

No problem at all! Happy to hear that you've got it all working!

cyberekklesia

Nov 15th, 2022 09:10 PM

Hello Bobby

After making some menu builder changes, I got the following error. This is the original code.

Any suggestions?

Thank you

bobbyiliev

Nov 16th, 2022 03:56 AM

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:

PHP: Scope Resolution Operator

Let me know how it goes!

Report
1
cyberekklesia

Nov 16th, 2022 05:17 PM

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.

Report
1
bobbyiliev

Nov 17th, 2022 03:28 AM

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