Illuminate\Database\Eloquent\Model::observe PHP Method

observe() public static method

Register an observer with the Model.
public static observe ( object | string $class, integer $priority ) : void
$class object | string
$priority integer
return void
    public static function observe($class, $priority = 0)
    {
        $instance = new static();
        $className = is_string($class) ? $class : get_class($class);
        // When registering a model observer, we will spin through the possible events
        // and determine if this observer has that method. If it does, we will hook
        // it into the model's event system, making it convenient to watch these.
        foreach ($instance->getObservableEvents() as $event) {
            if (method_exists($class, $event)) {
                static::registerModelEvent($event, $className . '@' . $event, $priority);
            }
        }
    }

Usage Example

 public static function boot()
 {
     parent::boot();
     parent::observe(new ProductTranslationObserver());
 }
All Usage Examples Of Illuminate\Database\Eloquent\Model::observe
Model