It is possible to create global scopes for the Models, but even if Global, it is still necessary to specify within your Model that it will have this implementation.
I want to create a Global scope that applies to all models.
Ref: link
It is possible to create global scopes for the Models, but even if Global, it is still necessary to specify within your Model that it will have this implementation.
I want to create a Global scope that applies to all models.
Ref: link
You could have the class Model
inherit the scope, but this would mean changing something on the Framework
base, which could imply future updates.
So I recommend the following:
Create a class to apply the scope and extend the Model
abstract class BaseModel extends Model
{
public static function boot()
{
parent::boot();
static::addGlobalScope(new BaseScope);
}
}
Then make your models extend from class BaseModel
.