Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

deepu07's avatar
Level 11

DB design best Practice

Hi Mates, in my project I have a requirement like counselors and clients related website. so coming to DB design I wanna create a three table one table for clients, a second table for counselors and a third table is the users. in the users' table, I just want to save the username/email/password/user_type_id. I'm just trying to understand what is the best practice for this scenario. also thinking to use a passport package for auth. so do you think is it best practice?

0 likes
5 replies
bugsysha's avatar

No. Just have users table with type column.

1 like
shami003's avatar

You can have just users table and then for different types of users use spatie permissions package

Ola-Yusuf's avatar

Well, this is similar to my ongoing project. For me, I prefer a different table each of the user type. In my project, I have :

  1. Table for Admin
  2. Table for Student
  3. Table for Academic Staff

Authentication type Oauth (Passport package) Then I control which table to use for authentication through the middleware.

Atef95's avatar

Stick with a single table it's better otherwise you'll be dupplicating the authentication system of laravel..

if you have different relationships for different users go for polymorphic relationships

1 like
Tray2's avatar

I would go with a single users table and then have user roles.

There are several ways of doing that.

  1. Add the role directly to the users table.
  2. Add a foreign key to the users table and have a roles table
  3. Use a pivot table to join the user and the role together.

Option 1 should only be used in a system with very few users.

id | username | role
-------------------------------------
1  | user1       | admin
-------------------------------------

Option 2 is for systems with many users

id | username | role_id
-------------------------------------
1  | user1       | 1
-------------------------------------

The role_id references the roles_table

id | role
---------------
1  | admin
---------------

Option 3 is for multi user systems with a possibility to let a user have multipple roles

Users table

id | username 
-------------------
1  | user1       
-------------------

roles table

id | role
---------------
1  | admin
---------------

role_users table

user_id| role_id
-------------------------------------
 1       | 1
-------------------------------------

The other upside to option 3 is that you can use the provided migrations and authentication out of the box.

1 like

Please or to participate in this conversation.