我有一个锦标赛和一个俱乐部模型。我使用them.now之间的多对多关系,我想找到一个使用透视表的俱乐部模型。
我试过了:
$tournament = Tournament::find(1);
$club = $tournament->clubs->wherePivot('team_as_1','1');
return $club;但是它表明:方法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的俱乐部。
发布于 2019-08-23 15:33:08
在下面使用
$tournament = Tournament::find(1);
$clubs = $tournament->clubs()->wherePivot('team_as_1','1')->get();
return $clubs;发布于 2019-08-23 15:15:51
试着做
$tournament = Tournament::find(1);
$club = $tournament->clubs()->wherePivot('team_as_1','1')->get();
return $club;使用当前的方法,您将在集合上调用方法wherePivot (但该方法不存在于集合类中),但是通过调用函数$ that >clubs(),该函数将返回一个查询构建器对象,您可以在该对象上调用wherePivot()
编辑:看起来你只需要一件东西,所以你可能应该这样做
$club = $tournament->clubs()->wherePivot('team_as_1','1')->first();发布于 2019-08-23 15:10:46
return $this->hasManyThrough('App\Club', 'App\Tournament');https://stackoverflow.com/questions/57621043
复制相似问题