简体   繁体   English

具有不同属性的多个角色 Laravel

[英]Multiple roles with different attributes Laravel

I have 3 roles for users: Admin, Editor, Normal user, and made a seperate table for roles, but my problem is that the (normal user) role have much more attributes/entries than the editor or the admin.我有 3 个用户角色:管理员、编辑器、普通用户,并为角色制作了一个单独的表,但我的问题是(普通用户)角色比编辑器或管理员具有更多的属性/条目。

Whats the best practice for it?最好的做法是什么?

Should I stick to the Users table and add those attributes as nullable?我应该坚持使用 Users 表并将这些属性添加为可为 null 吗? since the admin/editor does not need to fill it.因为管理员/编辑不需要填写它。

or make a new user_details table with one to one relation with the user?或者创建一个与用户具有一对一关系的新 user_details 表?

I would recommend going with a user_details table in this case.在这种情况下,我建议使用user_details表。

I often put non required fields for the other users nullable in users table migration file, And force them to be filled with code or logic (Request file).我经常在用户表迁移文件中将其他用户的非必填字段置为空,并强制它们填充代码或逻辑(请求文件)。 You can use in request validation required_if:role,normal您可以在请求验证中使用required_if:role,normal

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM