1 year ago

Laravel Eloquent triple table relation

Posted 1 year ago by bufferoverflow

Having three tables:

  • Teams
  • Users
  • Badges

A User can belong to many Teams, and Badges can be assigned for every User-Team.

Options i thought until now:

  • Create table "badges" with team_id and user_id as foreign.
  • Create pivot table "badge_team_user" and assign the 3 foreigns.

And which would be the best way to query the results?

  • $user->badges(team_id)
  • $team->badges(user_id)
  • $badges->printBadges(team_id, user_id)

Am i missing somethin better? Thanks!

Please sign in or create an account to participate in this conversation.