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

Rrrr's avatar
Level 1

Table design three types of users (admin, company, and student).

I'm trying to create a system that has three types of users (admin, company, and student).

so I have a student, company, and admin table.

my application case, after the admin adds student and company data. students or companies can log in using email and password without having to register.

How do I retrieve student or company data from the table and make it a user name and password for the login?

what is the design of the login table?and relation?

0 likes
7 replies
Tray2's avatar

A user is a user regrdless of type so you should only have one users table. Then you create a roles table and create your roles there (admin, company and student).

Then depending on if a user can have multiple roles or not you add the role_id to the users table or you create a role_users pivot table with the user_id and the role_id.

That will save you a lot of headache later on.

jlrdw's avatar

I agree:

RBAC is at least 3 main steps:

  • A login required
  • An authorization implementation to determine what the logged in person with role can or cannot do
  • Protection of URL and parameters, checking that the logged in users id matches the id used in a query Each application will require unique tweaks in RBAC, no two apps are exactly the same.

Query Scopes can be used to differentiate an admin from a user, and what data is shown in the query.

The out of box Authentication gives you everything you need no matter how many types of user.

You also set up authorization to determine who can and cannot do what.

And yes there is a learning curve involved.

Rrrr's avatar
Level 1

i want to create table company and student because later student or company can edit their data. and i want after admin add data student or company.student or company can login without register.

and i want to make coloumn on table student,email and password for login.it is possible?

or I have to make a separate table between student login and table for student data?

jlrdw's avatar

Laravel is very flexible so just Implement your custom RBAC however you think you need. Just FYI, you can do everything you described with the built-in authentication and authorization.

But of course you are free to do it customized also.

Rrrr's avatar
Level 1

Do you think Its possible,if im using polymorphic relations?

anoshiri's avatar

If I understand correctly what you want to achieve, you can use Laravel Guard to allow different classes of users to authentication using different DB Tables.

So you will have Admin table for Admin User, Company Table for company users and Student Table for student users. It's actually quite easy to do. This is a good article that can help you achieve that https://pusher.com/tutorials/multiple-authentication-guards-laravel

Please or to participate in this conversation.