Home > Software design >  How can I check two permissions in laravel gates using @can?
How can I check two permissions in laravel gates using @can?

Time:09-24

//e.g...
@can('view-post')
// show publish page
@endcan

//something like this.
@can('view-post') OR @can('publish-post')
// show publish page
@endcan

If the user have any of the user-rights, then access is granted.

CodePudding user response:

https://laravel.com/docs/8.x/authorization

You may also determine if a user is authorized to perform any action from a given array of actions. 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\Models\Post::class)
    <!-- The current user can create a post... -->
@endcanany

CodePudding user response:

Alternatively, in your blade:

    @if(Gate::allows('whatever') || Gate::allows('whatever-else'))
    <!-- Code --> 
    @endif
  • Related