laravel-permission icon indicating copy to clipboard operation
laravel-permission copied to clipboard

add blade directive hasanypermission

Open junaidiar19 opened this issue 1 year ago • 1 comments

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

junaidiar19 avatar Feb 12 '24 17:02 junaidiar19

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

parallels999 avatar Feb 29 '24 20:02 parallels999

canany() should work fine for this.

drbyte avatar Mar 01 '24 19:03 drbyte

Yes with @canany it works! thanks everyone

junaidiar19 avatar Mar 19 '24 08:03 junaidiar19