简体   繁体   中英

How can i assign user-list permission to other roles also in laravel for spatie package(ACL Management)?

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM