Answer the question
In order to leave comments, you need to log in
What is the best way to bypass the global scope in code?
Good afternoon.
There is a banal global scope that works for several related models:
abstract class ....
protected static function boot()
{
parent::boot();
static::addGlobalScope('is_not_archive', function (Builder $builder) {
$builder->where('archive', '=', 0);
});
}
Answer the question
In order to leave comments, you need to log in
The local scope, similarly to the global one, is bypassed through withoutGlobalScope(). In your context -
You can see more information in the official laravel documentation in the chapter on scopes . Post::withoutGlobalScope("is_not_archive")->get();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question