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

AbdulBazith's avatar

How to make users table common for different type of users? else do i need to change User registration table based on users in laravel??

Guys iam working with an online quiz examination project. i have a small doubt. basically user table is for registering users.

in my application iam the organization. my team has more than 5 users with different roles. I know about roles and permissions. our role is to upload questions in the db.

so lots of school will register and the staff memebers and students in the school are users of my application.

the role of staff is to create assessment by choosing the questions which is already stored in db.

after creating assessment student are requested to login and then write the exam. then results are verified.

Here my doubt is

as a oraganization iam also user here, the students and staff members of different schools also user here.

then how my user table must be changed.

this my structure

As my organization i will get

name
user_name
email
phno
password

these data are enough for my team. but when it comes to school say for example

AAA matriculation Higher Secondary school is registering to our application so i need to get the school info like school name, school address, school phno etc.

then i should register the student and staff members of that school like

Staff A belongs to this school with this username and this password with this role with this subject ( so that when the staff login he/she can see only maths questions)

Student B belongs to this school with this username and this password with this role and this class(then only those class assessments will be shown to him/her)

so my schoolDetails Table

id  name         address     phno
1   School1     Address1    123
2   School2     Address2    321
3   School3     Address3    547
.
.
so on

when registering staff or student of that school

id  school_id   name    username    email   password    phno
1       1       A       AAA          a@gm   **          122
2       1       B       BBB         b@gm    **          789

so if i i have a user table like above then how i can register my team??

overal my doubt is how to register my team, and other school in users table

i know that i will have a class table and subject table which will be linked to user table so based on the staff or student login that changes the display screen.

My major doubt how can i register myself and them??

0 likes
6 replies
Snapey's avatar

I prefer to use a single user model for ANYONE that needs authentication by your application.

So User model and users table is for authentication only

Then use roles and permissions to decide what the user is allowed to do

Attributes that are unique to each user type can be stored in profile tables which are linked to the user with a polymorphic relationship

http://novate.co.uk/using-laravel-polymorphic-relationships-for-different-user-profiles/

AbdulBazith's avatar

@bobbybouwmann thank you thank you sooo much guys.

Got some clear understandings. but still small doubt.

what i understood i will explain please check it. and kindly reply for thiss also then only ican get clear idea please please

schoolTable

id	name	adress	phno
1	AA		AA		123
2	BB		BB		321

PivotTable school_usser

school_id	user_id
1			1
1			2

userTable

id	name	username	password
1	abdul	abdul		***
2	Bazith	bazith		***

a user belongs to one school only then what is the necessary for many to many relationship?? if i make it as one to many relationship then where i should combine??

The condition is this if a pick a user from user table i should know to which school that user belongs to? whether he is staff or student??if staff which subject he is handling?? if student then which class he is studying?

and you said i can have a user - team relationship so that i can maintain team table to handle it.

But my team runs under one name. i have a single name for my team under that more than 10 users will be.

so for this i need to store my team name in separate table?

in school there will be many schools, so storing the school details in separate table is correct. but why i need to store my team name in separate table??

Kindly please reply for this, because i got half understanding. please clear this.

after seeing your answer whatever i thought i expressed here. is my asking is right??

please dont hesitate and answer .. then i will be still in confusing mode

AbdulBazith's avatar

@snapey thank you thank you sooo much.

the link gives me a clear idea. but please small doubt..

yes yes snapey. i understood. whatever user table iss used for authentication so if there is any need of unique columns can have seprate table am i right?? yes yes i understood.

but can you refer my above answer pleaseee please and can you suggest any idea??

Snapey's avatar

many questions

if a user can belong to many schools then this

The condition is this if a pick a user from user table i should know to which school that user belongs to?

is not possible, because the user has multiple schools

AbdulBazith's avatar

@snapey thank you for your response,

no one user belongs to one school only. that is if there is a student or staff, he.she will belong to one school only.

he can't be in two schools..

and another doubt, we can have additional data in pivot table?? additional data means can give a small example?

Please or to participate in this conversation.