I use global scope based on the current auth but getting error: Integrity constraint violation: 1052 Column 'status' in where clause is ambiguous
Is it possible to get the table name for the current model inside of addGlobalScope
? E.g Without $this
needed for qualifyColumn.
` protected static function boot() { parent::boot();
if (!auth()->user() || !auth()->user()->isManagement()) {
static::addGlobalScope('valid', function (Builder $builder) {
$builder->where($this->qualifyColumn('status'), 1);
});
}
}
`
This just gets messy having to pass the name
` protected static function boot() { parent::boot();
$table_name = 'employment_contracts';
if (!auth()->user() || !auth()->user()->isManagement()) {
static::addGlobalScope('valid', function (Builder $builder) use($table_name) {
$builder->where("{$table_name}.status", '=', AbecederSystem::$ENABLED);
$builder->where(function ($q) use($table_name) {
$q->where("{$table_name}.valid_from", '<=', Carbon::now());
$q->where(function () use ($q, $table_name) {
$q->where("{$table_name}.valid_until", '>=', Carbon::now())
->orWhereNull("{$table_name}.valid_until");
});
});
});
}
} `
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community