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

lucassimines's avatar

How can I use @can with multiple user permissions?

Hello guys, Based on Jeffrey`s ACL lessons, I created my ACL on L5. But I would like to use @can() with more than one permission, like:

@can('edit_pages','edit_posts')

But I think there isn't a way to do this with @can(), what's the best way to do it? Thanks in advance.

0 likes
14 replies
zachleigh's avatar

Good question. Did you try an array?

@can(['edit_pages','edit_posts'])
lucassimines's avatar

@zachleigh Doesn't work too.

Maybe @can() really just works with a single parameter.

But, I found a solution:

@if($user->can('edit_pages') || $user->can('edit_posts'))
    // do something
@endif
2 likes
martinbean's avatar

@lucassimines Why are you checking multiple permissions? You should only need to check the permission around the resource you’re trying to modify.

Ben Taylor's avatar

@martinbean I have a use case for this. I've got an admin navigation with nested links grouped by certain categories. I want to hide links that users don't have permission to access. If a category contains sublinks, I only want to hide the category as a whole if the user doesn't have permission to access any of the sublinks.

1 like
lucassimines's avatar

@martinbean yes I know, but what I'm doing is:

If user can Full Edit (Admin) or Manage Pages, do something.

To don't need to add the permissions I create everytime into my Admin role sometimes I can check if my user can Full Edit also.

EkloSahas's avatar

use the Gate of Facades as

@if(Gate::check('permission1') || Gate::check('permission2'))

@endif

instead of multiple @can

1 like
shabayekdes's avatar

You may also determine if a user has any authorization ability from a given list of abilities. To accomplish this, use the @canany directive:

@canany(['update', 'view', 'delete'], $post) // The current user can update, view, or delete the post @elsecanany(['create'], \App\Post::class) // The current user can create a post @endcanany

3 likes

Please or to participate in this conversation.