0

withoutGlobalScope()如果条件为真,我需要使用。我已经尝试过使用 when 函数。但它只在函数之外起作用。

这是我的模型

 protected static function boot()
{
    parent::boot();

    static::addGlobalScope('active', function (Builder $builder) {
        $builder->where('vehicles.active', 0);
    });
}

这是雄辩的查询

$this->model
        ->when((isset($attbutes->inactive) && $attbutes->inactive==1), function ($q) use ($attbutes) {
            return $q->withoutGlobalScope('active');
        })
        ->get();
4

0 回答 0