Laravel Authorize Multiple Permission

674 Views Asked by At

I want to control the index of my controller via two permissions, the user must have either 'Permission1' or 'Permission2'. Both together is also possible.

Currently I check for one permission:

$this->authorize('Permission1');

I have tried:

$this->authorize('Permission1' || 'Permission2');
$this->authorize(['Permission1' || 'Permission2']);
$this->authorize(['Permission1', 'Permission2']);

Controller Constructor:

public function __construct()
{
    $this->middleware('auth');

    $this->middleware('permission:' . Permission::PERMSSION1, ['only' => [
        'permission1',
    ]]); // Here I don't know how to adjust it too
}

And a few more, but nothing seems to work.

How can I query the authorization for Permission1 OR Permission2?

1

There are 1 best solutions below

2
noisedaddy On

Did you tried with $this->authorizeEither('Permission1', 'Permission2'); ?