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

Soo's avatar
Level 2

link candidat table with user table

Hello friends, i have a table candidat heritage table user. i want to link candidat table with user table . Also i have roles table contain four roles ( super admin , admin , human resource and candidat ) . how can i link candidat table with user table that her role is candidat ( to create account for the candidat).

0 likes
1 reply
automica's avatar
automica
Best Answer
Level 54

its best for you to identify which relationship each model has with each other.

  • anyone that needs to login needs to be a User
  • if aUsercan also be a Candidate, then in your Candidatemodel you will want to add a user_id and define hasOne relationship User hasOne Candidate.
  • User can have many roles, and Role can have many User so you want to define a belongsToMany relationship both ways between those models.

depending on the complexity of your Role its best to assign Permissions to Role with a package such as https://github.com/spatie/laravel-permission

1 like

Please or to participate in this conversation.