how to dynamically show hide/menu elements

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?

Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (3)

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'],
),

You can create a role in your controller and assign it to the user.

$role = Role::create(['name' => 'admin']);
auth()->user->assignRole('admin');

For more information about the permission plugin, please check the docs here;
https://spatie.be/docs/laravel-permission/v5/introduction


Thanks

great that looks exactly right thank you!

No problem. Glad it helps you.

Thanks

Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(