如何在范围内使用 wherePivot 方法?

How to use wherePivot method in a scope?

我有两个带枢轴的模型。

Domain
{
    public function projects()
    {
        return $this->belongsToMany('Project')->withPivot('is_live');
    }
}

Project
{
    public function domains()
    {
        return $this->belongsToMany('Domain')->withPivot('is_live');
    }
}

然后我尝试像那样创建范围 "Domains which have Projects and is_live = true" Laravel Scope by pivot data values

public function scopeHasLiveProjects($query)
{
    $pivotTable = $this->projects()->getTable();
    return $query->whereHas('projects', function ($q) use ($pivotTable) {
            $q->where($pivotTable . '.is_live', true);
    });
}

但是我如何使用 eloquent 方法 wherePivot('is_live', '=', true)在范围内?可能吗?!

public function scopeHasLiveProjects($query)
{
    return $query->whereHas('projects', function ($q) {
            $q->where('is_live', true);
    });
}

应该做需要的事