0

I am using Spatie package for ACL Management in Laravel and its working perfectly but i want to ask one question.If i have to assign user-list permission to any role like Manager even it has permission then it generates an error. and what is the purpose of 'only' attribute below in constructor and 'permission:role-list' doesn't assign any function, is there any default behavior?

function __construct()
{
    $this->middleware('permission:role-list');
    $this->middleware('permission:role-create', ['only' => ['create','store']]);
    $this->middleware('permission:role-edit', ['only' => ['edit','update']]);
    $this->middleware('permission:role-delete', ['only' => ['destroy']]);
}

should i assume if i have to access any function of role controller than it must have role-list permission in Spatie.

Please guide me if i am thinking wrong.

apokryfos
  • 38,771
  • 9
  • 70
  • 114
hu7sy
  • 983
  • 1
  • 13
  • 47
  • Answer for the second part of your question is listed below, And for the first part as you said it generates error, Please paste the error in description as well. – Khurram Shahzad Feb 28 '19 at 08:06
  • it just showing me it does't have specific permission if i assign role-list permission then it works smoothly – hu7sy Feb 28 '19 at 08:09

2 Answers2

0

To restrict the middleware to only certain methods on the controller class we use only.

$this->middleware('permission:role-create', ['only' => ['create','store']]);

Now the above lines only applies the listed middleware on create and store method.

Khurram Shahzad
  • 167
  • 2
  • 10
0

i am telling answer to my own question, in constructor if i have first method without any permission assign to method below.

 $this->middleware('permission:role-list');

so if any role doesn't have this permission it generate an error the role doesn't have permission for this and it does not check next permission.

hu7sy
  • 983
  • 1
  • 13
  • 47