Eloquent cant manage a 3 ways pivot, you can use this package.
Relate three models with extra info
Hi all,
I´m updating myselft on Laravel 5 with a little project but I´m getting in an endless mess.
I´ve been looking for similar questions about my situation but I´ve haven´t found any good clue about this "usual" problem. All I´ve read is about two models with pivot table but what about three.
The scenario is next.
Three models: Season | Team | Player
I have create a forth model to relate then and to know how many games a player has played.
Profile:
- season_id
- team_id
- player_id
- games_played
In player model I define the relation: function played() { $this->hasMany('App\Profile','player_id','id); }
In the Profile model I define the relation: function player() { $this->belongsToMany('App\Player','player_id'); }
The question is, how should I do, or which additional relation should I define to show all the seasons with all the teams and the games played by a player?
Thanks.
Please or to participate in this conversation.