DocsMenuMenus-in-your-laravel-appConditional Items Based on Permissions
You are viewing the documentation for an older version of this package. You can check the version you are using with the following command:
composer show spatie/menu
Conditional Items Based on Permissions
v1.1+
The add method and all convenience methods (link, html, action,...) have an equivalent method with an IfCan suffix. When used, the item will only be added if the currently logged in user has a certain permission.
<!-- User isn't logged in or can't view posts -->
<ul>
<li><ahref="/">Home</a></li>
</ul>
<!-- User is logged in and can view posts -->
<ul>
<li><ahref="/">Home</a></li>
<li><ahref="/posts">Posts</a></li>
</ul>
If your permission check requires parameters, you can provide an array for the permission. The permission's name should be the first element, and parameters should fill up the rest.