protected static function boot()
    {
        parent::boot();

        // Boot event for creating this model.
        // Set default values if specified.
        // Validate dirty attributes before commiting to save.
        static::creating(function ($model) {
            $model->setDefaultValuesForAttributes();
            if (!$model->savingValidation()) {
                $validator = $model->getValidator();
                $issues = $validator->errors()->all();

                $message = sprintf(
                    "Validation failed on creating %s.\n%s",
                    $model->getTable(),
                    implode("\n", $issues)
                );

                throw new Exceptions\ValidationException($message, 0, null, $validator);
            }
        });

        // Boot event once model has been created.
        // Add missing attributes using the schema.
        static::created(function ($model) {
            $model->addMissingAttributes();
        });

        // Boot event for updating this model.
        // Validate dirty attributes before commiting to save.
        static::updating(function ($model) {
            if (!$model->savingValidation()) {
                $validator = $model->getValidator();
                $issues = $validator->errors()->all();

                $message = sprintf(
                    "Validation failed on saving %s (%s).\n%s",
                    $model->getTable(),
                    $model->getKey(),
                    implode("\n", $issues)
                );

                throw new Exceptions\ValidationException($message, 0, null, $validator);
            }
        });
    }