Support the ongoing development of Laravel.io →
Eloquent Database

I am building a fairly complex application that will store many different user factors. In theory, each User should belong to a department. Each department will have a set of ranks that the user may belong to.

What I have:

  1. A users table with department_id and rank_id.
  2. A departments table with id and name.
  3. A table "example_department" (different name, but for this threat, it's example) with rank_id, rank_name, department_id.

I am not sure which relationships to use, or if I am even doing this the correct way.

Does anyone have any ideas?

Last updated 3 years ago.
0

By what I've understood your relationship should look this:

  • User belongsTo Department
  • User belongsTo Rank
  • Department hasMany User
  • Rank hasMany User

Sorry if I misunderstood your project.

Last updated 8 years ago.
0

Clarification:

  • Users Table:

    • department_id
    • rank_id
  • Departments Table:

    • id
    • name
      • The name here will have another table to go with it (example: example_department.)
  • example_department Table:

    • rank_id
    • rank_name
    • department_id
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Austin Sharp Austin Sharp asharp Joined 2 Jul 2017

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.