@deebow Would a tournament not be made up of multiple games? Personally, I’d have a Game model, that then has many “participants”, which would be your polymorphic relation (a “participant” would either be a club or individual player).
For tournaments, I’d just have a has-many relation to games. Again, you could add a has-many polymorphic relation to participants if you wanted to show what clubs/players were playing in a tournament, but players in the constituent games had not been decided yet (e.g. matches still needed to drawn).
So you’d have the following tables:
clubs
players
games
tournaments
game_participants
tournament_participants
You could try and be “clever” and create some sort of “participants” table with two polymorphic relations linking a club/player to a game/tournament, but for the sake of clarity I’d just have a table each for games and tournaments, otherwise your queries and model relations may get a bit gnarly.
Can a club/player really participate in a tournament? Or in fact they can participate in a game which is a part of a tournament?
Can a player participate in a game/tournament by himself, without a club?
Maybe your real relations are:
Player -> belongsTo -> Club
Club -> hasMany -> Player
Club -> belongsToMany -> Game
Game -> belongsToMany -> Club
Game -> belongsTo -> Tournament
Tournament -> hasMany -> Game
And Player is related to a Tournament/Game not directly but through several other relations.
Do you mind sharing what sports is this relates to? In general knowledge, it seems like player participate in a game, which belongs to a tournament. Can player be part of a tournament with out being part of a game?
Second layer is , can a player participate in a game without being part of a club? If they cant, then again players belong to club, club participates in game, which is belongs to a tournament.
Athlete -> BelongsTo -> Club
Club -> HasMany -> Athlete
Game -> BelongsTo -> Tournament
Tournament -> HasMany -> Game
I could go with contenderables, having 2 polymorphic columns for game/tournament and athelte/club, but it seems very complex, and I just want to simplify things, so I ended up with the following:
Although I'm having problems with making barryvdh/laravel-ide-helper work with this.
The problem is, I decided to make these pivot into a model extending Illuminate\Database\Eloquent\Relations\MorphPivot, since there are additional columns to each pivot, and it's much easier to manipulate it this way:
game_participants
- game_id
- participantable
- more columns...
tournament_participants
- tournament_id
- participantable
- more columns...
Now, since ide-helper expects the MorphPivot model to have a singular database migration, like game_participant and tournament_participant... it can't be analyzed, so it's not generating the necessary docblocks.
Ahh, silly... I could specify the table name in the model protected $table = 'game_participants' for example... then the ide-helper will then recognize it.