我需要为查询做一个if语句,我需要检查列status
是否被设置为rematch
,以便在数据透视表player_quiz
中进行测试。以下是quiz
模型中建立关系的方法:
public function players()
{
return $this->belongsToMany('App'Player', 'player_quiz')->withPivot('status');
}
我不确定如何做这种查询,让它更清楚这里它应该基本上看起来像:
if ($quiz->players()->where('status', 'rematch'))->get();
试试这个:
if ($quiz->players()->wherePivot('status', 'rematch')->get()) {
// Do something
}