Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

engrlaravel's avatar

checking both roles & permission at the same time

I am using laravel-permission package. I want to show HR menu only to HR & Admin roles and who has permission to HR menu.

 @role('HR|Admin')
<a href="{{ url('hr') }}">HR Menu</a>
 @endrole

How i can combine permission to above condition?

permission alone i can use like this

@can('edit articles')
  <a href="{{ url('hr') }}">HR Menu</a>
@endcan
0 likes
4 replies
Sti3bas's avatar
Sti3bas
Best Answer
Level 53

You can always use native @if directive to combine multiple checks: @if($user->hasAnyRole(['HR', 'Admin']) || $user->hasPermissionTo('edit articles'))

But it's recommended to code your app around permissions only. That way you can always use the native Laravel @can.

RoboRobok's avatar

In my opinion, can() is better when we want to check permission to do something, but checking entire role also makes sense in some cases. For instance, if we want to display entire dashboard area, it sometimes more sense to show/hide it through roles instead of checking individual permissions, which in theory are more dynamic.

Sti3bas's avatar

@roborobok it's always good to have this flexibility in long term especially when you don't know if there will be more roles in the future.

And I don't see any benefits for checking the role instead of permission (e.g. view dashboard) in your example.

RoboRobok's avatar

I mean situation when each role has their own dashboards. I understand your point and I agree that permission-driven system is better in most cases, just like feature checking is better than browser checking. But there are exceptions. Adding artificial permissions (like view_editor_dashboard) just to follow this rule is not the greatest idea. As well as checking multiple permissions to guess what is the user's context.

Please or to participate in this conversation.