【发布时间】:2017-10-22 17:11:50
【问题描述】:
我有两个多对多关系表countries and teams table。在我的国家表中,有president_id。现在我想使用连接查询来获取属于该总统 ID 的团队,但我无法实现这一点。
我如何才能选择属于特定总裁的所有团队?
PS:新手用 laravel
国家
public function teams()
{
return $this->belongsToMany('App\Team');
->withTimestamps();
}
团队
public function countries()
{
return $this->belongsToMany('App\Country')
->withTimestamps();
}
控制器
$teams = Team::all()->with('countries')->where('president_id,1)->first();
$getTeams = $teams->pluck('id')->toArray();
【问题讨论】: