skip to Main Content

I need to assign 4 roles.
The role has User , Manager , Admin , Super Admin

and some User will have 2 roles

each role There will be different personal information.
and giving a role to User will go through Register

I’m not sure what’s the best way to create a table.

I’m supposed to create 4 tables separated by roles.
Or how should I create the table?

please help me

and if possible I would also like to know how to set roles for page access. or query MySql

2

Answers


  1. Created two tables will be needed. One table for roles with (userid and roles_name), another table for the user table with (roles_id) column, roles_id is foreign key from the roles table.

    Login or Signup to reply.
  2. You can try creating 3 tables Users, Roles and User has Roles as follow

    User table

    users

    id name email
    1 super admin [email protected]
    2 admin [email protected]
    .. .. ..

    Role table

    roles

    id name
    5 Super Admin
    6 Admin
    .. ..

    User has Roles table

    user_has_roles

    user_id role_id
    1 5
    2 6
    .. ..

    To assign role to any users you can assign it by passing role_id and user_id in user_has_roles table

    Here is sample SQL schema

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search