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

gocevskam's avatar

Connection between 2 different user roles

It am working on an application with psychological tests (questionnaires ). I have roles of a doctor, patient and admin.

Patients should be able to answer the questionnaires online, but also on paper. So when the second is true (on paper), the doctor(its secretary) should be able to enter this information to the patient's profile.

How to do I make the connection of doctors and patients, (when they are both users), so that a doctor is able to fill in questionnaires for his patients?

When I associate a questionnaire with the user, then if a doctor would want to register this information it should instead login with the patient credentials (which wouldn't be very practical).

Any ideas of how can I achieve it?

0 likes
6 replies
pmall's avatar

Doctor hasMany Patient.

That's all no ?

mstnorris's avatar

If a USer has a Role of Admin then they see a form that allows them to select their Patient's (Users) details.

There are many lessons here that will give you more information about how to achieve this. Namely Roles and Permissions, especially the new Laravel 5.1 lessons published a few days ago.

gocevskam's avatar

@pmall I don't have the Doctor and Patient Models, just a User Model, this is why it is hard for me to figure it out.

pmall's avatar

Yes but users table can have a nullable doctor_id column so it can belongsTo another user (his doctor). So if a user has doctor role it can fill its children users forms.

1 like
gocevskam's avatar

@mstnorris Thanks for your reply, I watched the lesson about the Roles and Permissions, it is how I could make the roles. Maybe my problem is that the way I have make the questionnaire. It a form that when the user fills it in it gets saved to the database (like creating a flyer/new post). It is why the admin will not be able to edit it if it is not existing and if he creates one it would be associated with its user_id.

pmall's avatar

You have an url for the form right ? Something like : /users/{user_id}/questionnaires/{questionnaire_id}.

From there any user can access this url, than you check permission here. If the user is a doctor and user_id is one of his patient he can access the form.

1 like

Please or to participate in this conversation.