laravel - 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?
解决方案
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.
推荐阅读
- ruby-on-rails - 根据其他哈希数组的键值更新一个哈希数组
- react-native - 如何在平面列表中隐藏/显示文本输入反应原生?
- java - Java.lang.IllegalStateException:罐子地狱!在弹性 6.5.1 中
- sapui5 - getRows 低于模型长度
- aem - AEM - Sling Page 对象不一致
- java - 使用 Spring 防止注入范围更窄的 bean
- java - 如何将 GifDrawable(Glide 4)转换为 InputStream?
- swift - 如何在 animateKeyframes 中计算 relativeDuration
- database - SPARQL,dbpedia:检索链接为属性的资源的值,类型人员
- angular - Angular 4 - 如何使用相同的组件作为两个不同父组件的子路由器?