I want to have matches with 2 teams in my App. Currently I implemented this with a simple hasMany/belongsToMany relationship.
Tables: teams, matches, match_team (match_id, team_id)
Team Model
...
public function matches()
{
return $this->belongsToMany('App\Match');
}
Match Model
...
public function teams()
{
return $this->belongsToMany('App\Team');
}
So of course I have 2 rows for each match in the Pivot table match_team:
match_id team_id
1 1000
1 2000
2 3000
2 4000
With Blade templating engine I can request f.e. the home team like:
{{$match->teams[0]->name}}
But I want to be more specific and want to have a table like this:
match_id host_team guest_team
1 1000 2000
2 3000 4000
But then I don't really know how to set those relationships...
Any thoughts/ideas on that? =)