Php Laravel-从关系查询数据透视表中的列值
我需要为一个查询做一个if语句,其中我需要检查pivot表Php Laravel-从关系查询数据透视表中的列值,php,mysql,laravel,eloquent,Php,Mysql,Laravel,Eloquent,我需要为一个查询做一个if语句,其中我需要检查pivot表player\u quick中该测验的玩家的列status是否设置为rematch。 这是如何在测验模型中设置关系: public function players() { return $this->belongsToMany('App\Player', 'player_quiz')->withPivot('status'); } 我不确定如何进行此类查询,以便在这里更清楚地说明它的基本外观
player\u quick
中该测验的玩家的列status
是否设置为rematch
。
这是如何在测验
模型中设置关系:
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
}