laravel-permission
laravel-permission copied to clipboard
add blade directive hasanypermission
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 :)
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
canany() should work fine for this.
Yes with @canany it works! thanks everyone