I'm a bit confused.... just wonder why not user has many roles, and a role have many permissions?? so your user just need to bind with roles... and the role have it binding with permissions...
Multiple polymorphic xxxxable_type fields in table
Hi every one ! I'm building my own user / roles system and I've run intro a problem. I have the following tables :
-
users id, name, etc...
-
roles id, slug, tilte
-
role_user (pivot table) user_id, role_id
This is very basic. Next I have my permission table. Actually I have multiple permissions table:
-
permission_groups id, slug, title
-
permissions id, permission_group_id, slug, title
-
permission_functions id, permission_id, slug title
So I want to be able to assign, many to many roles - permissions, and many to many user-permissions. I was thinking on creating 2 polymorphic tables.
First would be :
-
userable user_id, userable_type ( model permission or model permission_ group or model permission_functon ), and a userable_id
-
rolable role_id, rolable_type ( model permission or model permission_ group or model permission_functon ), and a rolable_id.
So my question is, instead of creating 2 polymorphic tables (userable and rolable), is there a way to have a multiple polymoprhic fields i, a single table ? I would like to have a table that looks like :
- assignable assignable_type_1 ( roles or users models), assignable_id_1 assignable_type_2 (permission group, permissions or permission funtcions) assignable_type_id_2
This is something of course possible if doing it from scratch, nut i was wondering if Laravel's polymorphic system can handle this ? I'm working on the version 8 of Laravel. Thanks in advance and happy code !
Please or to participate in this conversation.