Skip to content
Advertisement

Laravel relation from a pivot

I have a relation that I cant figure out my current application looks like this

Models

JavaScript
JavaScript
JavaScript

Tables

JavaScript
JavaScript
JavaScript

Now a tournament can have just some of the users participate in the tournament so I’ve created the below

JavaScript

To store users that are participating in a tournament from the team.

How should this look in terms of eloquent relations?

Advertisement

Answer

So taking your team_tournament_users, I would do the following

Would use the naming convention participants of tournament, so table name would be participants instead of team_tournament_users

Migration

JavaScript

Relationships: Then would define the following relationships in models

JavaScript

How would I then go about retrieving all the users participating in the team for a specific tournament? So if 3 users/members from a team are selected for the tournament how can I easily find out which members from that team are selected?

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement