Laravel Spatie Custumize model_has_roles表

发布于 2025-01-29 05:32:32 字数 589 浏览 3 评论 0原文

我更改了 model_has_roles 表。我在 model_has_roles 表中添加了 domain_id 表没有问题。 现在,我有一个具有两个域的用户。例如,我在admin的ABC.com角色中有Jhon Doe,还有XYZ.com的Jhon Doe在编辑中。当我使用auth :: user() - >角色函数时,功能同时返回管理员和编辑器角色。我想要根据我想要的域名角色。

自定义model_has_roles表

prole_idmodel_typemodel_iddomain_id
2app \用户217
6应用程序\用户216

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_idmodel_typemodel_iddomain_id
2App\User217
6App\User216

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

双马尾 2025-02-05 05:32:32

我想您会找到一个答案,但是如果没有答案,可以查看 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);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文