Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add blade directive hasanypermission #2610

Closed
wants to merge 2 commits into from
Closed

Conversation

junaidiar19
Copy link

I have an issue when I want to protect my navbar heading menu

For Example:
[Navbar Heading]
MASTER DATA
[Navbar Menu]

  • Master User
  • Master Product
  • Master Promo

And that I try to protect my navbar heading with permission like so:

@can('show master user|show master product|show master promo')
   <li class="nav-item">
       <div class="navbar-heading">MASTER DATA</div>
   </li>
@endcan

That's mean the user must be have all the permissions for showing the navbar-heading, but I want the user just have one of the permission for showing it.

So, then I edit my code like so:

@if (auth()->user()->hasAnyPermission([
            'show master user',
            'show master product',
            'show master promo',
        ]))
    <li class="nav-item">
        <div class="navbar-heading">MASTER DATA</div>
    </li>
@endif

And it's works!

That's why I decided to add new blade directive hasanypermission.

Thank's, I hope this PR will be approved :)

@parallels999
Copy link
Contributor

Did you try @canany?

@canany(['show master user', 'show master product', 'show master promo'])
   <li class="nav-item">
       <div class="navbar-heading">MASTER DATA</div>
   </li>
@endcanany

@drbyte
Copy link
Collaborator

drbyte commented Mar 1, 2024

canany() should work fine for this.

@junaidiar19
Copy link
Author

Yes with @canany it works! thanks everyone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants