How to create a truly global Global Scope

0

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

    
asked by anonymous 13.04.2018 / 17:02

1 answer

0

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 .

    
16.04.2018 / 16:12