dimanche 20 mai 2018

Laravel Eloquent triple table relation

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:

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

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

  1. $user->badges(team_id)
  2. $team->badges(user_id)
  3. $badges->printBadges(team_id, user_id)


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2LgyICv
via IFTTT

Aucun commentaire:

Enregistrer un commentaire