首页 > 解决方案 > Using Spatie's Laravel Permission Package, how can I assign multiple roles to a user?

问题描述

I have many accounts, and many users. A user should have a role of manager in one agency but also a role of customer in another account.

Is it possible to use Spatie's Laravel permissions package (https://docs.spatie.be/laravel-permission/v3/introduction/) for this? For example a permission may exists called can delete accounts, but this should only be valid for certain accounts. The default functionality of the package would mean that a user with the permission can delete accounts would allow them to delete ANY account instead of only the account which they are a manager of.

I was thinking to have a many-to-many table users_roles, with fields user_id, role_id, role_name.

Is there any documentation on this? Or anyone accomplished this with the package?

标签: laraveluser-permissions

解决方案


Not out of the box with Spatie's Laravel Permission.

But you can write your own gates in Laravel: https://laravel.com/docs/7.x/authorization#gates

Check your current version docs as it might defer.


推荐阅读