Get 2024 Templates Mega Bundle!$1000 worth of 19 Bootstrap HTML, Vue & React Templates + 3 Vector Sets for just $99
Get for 99$

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 (5)


Really fun to know this. The tools used for the program need to be precise. Learn more experiences while building geometry dash lite on the programming language.



To dynamically show or hide menu elements in a web page, you can use JavaScript (or a library like jQuery) combined with CSS.



No problem. Glad it helps you.

Thanks



great that looks exactly right thank you!



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


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  :(