Laravel Spatie Custumize model_has_roles表
我更改了 model_has_roles 表。我在 model_has_roles 表中添加了 domain_id 表没有问题。 现在,我有一个具有两个域的用户。例如,我在admin的ABC.com角色中有Jhon Doe,还有XYZ.com的Jhon Doe在编辑中。当我使用auth :: user() - >角色
函数时,功能同时返回管理员和编辑器角色。我想要根据我想要的域名角色。
自定义model_has_roles表
prole_id | model_type | model_id | domain_id |
---|---|---|---|
2 | app \用户 | 2 | 17 |
6 | 应用程序\用户 | 2 | 16 |
I changed model_has_roles table.I added domain_id in model_has_roles table there is no problem with that.
Now, I have one user with two domain. For instance, i have jhon doe in abc.com role with admin and also jhon doe in xyz.com role with editor. When i use Auth::user()->roles
function, function returns both admin and editor roles. i want roles according to domain which i want.
custom model_has_roles table
role_id | model_type | model_id | domain_id |
---|---|---|---|
2 | App\User | 2 | 17 |
6 | App\User | 2 | 16 |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想您会找到一个答案,但是如果没有答案,可以查看 https://spatie.be/docs/laravel-permission/v5/basic-usage/teams-permissions
您可以定义
'teams'=> true
,'team_foreign_key'=> 'domain_id'
以及之后,在您的家庭控制器或其他检查角色和权限的中间件,您可以添加以下内容:
setpermissionSteamId(domain_id);
I suppose you find an answer but if it's not, you can look at https://spatie.be/docs/laravel-permission/v5/basic-usage/teams-permissions
You can define
'teams' => true
,'team_foreign_key' => 'domain_id'
And after, in your Home controller, or other middleware which check role and permission, you can add this :
setPermissionsTeamId(domain_id);