【发布时间】:2019-08-23 23:44:53
【问题描述】:
我有一个锦标赛和一个俱乐部模型。我在它们之间使用多对多关系。现在我想使用数据透视表找到一个俱乐部模型。
我试过这个:
$tournament = Tournament::find(1);
$club = $tournament->clubs->wherePivot('team_as_1','1');
return $club;
但它显示:Method Illuminate\Database\Eloquent\Collection::wherePivot 不存在。
我的锦标赛模型:
public function clubs(){
return $this->belongsToMany('App\Club','tbl_club_tournament')->withPivot('team_as_1','team_as_4','team_as_5','team_as_6');
}
我的俱乐部模型:
public function tournament(){
return $this->belongsToMany('App\Tournament','tbl_club_tournament')->withPivot('team_as_1','team_as_4','team_as_5','team_as_6');
}
我想找到一个 team_as_1 = 1 的俱乐部。
【问题讨论】: