![](/img/trans.png)
[英]Showing multiple roles assigned to a user in Laravel using Spatie Permissions
[英]How to assign multiple roles and multiple roles based permissions uning laravel spatie?
我正在开发一个 laravel 项目,该项目对以下用户具有基于角色的访问权限:
1 admin -> all permissions
2 creator -> add, edit and remove members
3 finance -> add fund, update fund
the problem is, a user, say "XYZ" has multiple roles like creator and finance and another user "PQR" has only finance
通过使用“Spatie laravel 权限”我该如何实现?
对于用户“XYZ”
我们可以将相关角色创建者和财务作为数组传递给 controller,
然后,
$user->assignRole($request->role);
// $user->assignRole(['creator', 'finanace']) 或 $user->assignRole('creator','finance')
对于用户“PQR”
和上面一样,
$user->assignRole($request->role);
// $user->assignRole(['finance']);
更多细节可以参考官方文档。 https://spatie.be/docs/laravel-permission/v3/basic-usage/role-permissions
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.