アプリで 2 つのチームと対戦したいです。現在、単純な hasMany/belongsToMany 関係でこれを実装しています。
テーブル: チーム、マッチ、match_team (match_id、team_id)
チームモデル
...
public function matches()
{
return $this->belongsToMany('App\Match');
}
マッチモデル
...
public function teams()
{
return $this->belongsToMany('App\Team');
}
もちろん、ピボット テーブルの match_team には、試合ごとに 2 つの行があります。
match_id team_id
1 1000
1 2000
2 3000
2 4000
Blade テンプレート エンジンを使用すると、ホーム チームに次のようにリクエストできます。
{{$match->teams[0]->name}}
しかし、私はより具体的にしたいので、次のようなテーブルが必要です:
match_id host_team guest_team
1 1000 2000
2 3000 4000
しかし、それらの関係を設定する方法がよくわかりません...
それについて何か考え/アイデアはありますか?=)