带参数分组的关系查询
Relation Querying with parameter grouping
我对模型有以下查询 - 但是仅查询团队比赛的条件仅适用于第一个 where 子句。
$this->matches = $this->team->matches()->whereNull('wbp')->orWhere(function($q) {
$q->whereNotNull('wbp')->where('is_played','=',0);
})->get();
如果我单独使用它们,它们会正常工作——它们都应该返回一个项目:
$this->team->matches()->whereNull('wbp')->get();
$this->team->matches()->where(function($q) {
$q->whereNotNull('wbp')->where('is_played','=',0);
})->get();
但是链接它们只会给我 wbp 为空的所有球队比赛,以及 wbp != null 和 is_played = false 的任何球队的所有比赛。
如何在此处正确链接它?
我需要在 matches() 调用上链接 where:
$this->matches = $this->team->matches()->where(function ($q)
{
$q->whereNull('wbp')->orWhere(function($q)
{
$q->whereNotNull('wbp')->where('is_played','=',0);
});
})->get();
我对模型有以下查询 - 但是仅查询团队比赛的条件仅适用于第一个 where 子句。
$this->matches = $this->team->matches()->whereNull('wbp')->orWhere(function($q) {
$q->whereNotNull('wbp')->where('is_played','=',0);
})->get();
如果我单独使用它们,它们会正常工作——它们都应该返回一个项目:
$this->team->matches()->whereNull('wbp')->get();
$this->team->matches()->where(function($q) {
$q->whereNotNull('wbp')->where('is_played','=',0);
})->get();
但是链接它们只会给我 wbp 为空的所有球队比赛,以及 wbp != null 和 is_played = false 的任何球队的所有比赛。
如何在此处正确链接它?
我需要在 matches() 调用上链接 where:
$this->matches = $this->team->matches()->where(function ($q)
{
$q->whereNull('wbp')->orWhere(function($q)
{
$q->whereNotNull('wbp')->where('is_played','=',0);
});
})->get();