diff --git a/src/Traits/Securable.php b/src/Traits/Securable.php index 55ec56f..de78ed1 100644 --- a/src/Traits/Securable.php +++ b/src/Traits/Securable.php @@ -18,21 +18,26 @@ trait Securable public static function bootSecurable(): void { static::updated(function (Model $model) { - if (config('security-notifications.send_notifications')) { - $changedSecureFields = collect($model->getChanges())->only($model->getSecureFields()); - - if ($changedSecureFields->count()) { - event(new SecureFieldsUpdated( - $model, - $changedSecureFields->toArray(), - $model->sendSecurityEmailsTo(), - $model->refresh()->updated_at, - )); - } - } + self::handleUpdatedSecureFields($model); }); } + public static function handleUpdatedSecureFields(Model $model): void + { + if (config('security-notifications.send_notifications')) { + $changedSecureFields = collect($model->getChanges())->only($model->getSecureFields()); + + if ($changedSecureFields->count()) { + event(new SecureFieldsUpdated( + $model, + $changedSecureFields->toArray(), + $model->sendSecurityEmailsTo(), + $model->refresh()->updated_at, + )); + } + } + } + public function sendSecurityEmailsTo(): string { return $this->getOriginal('email') ?? $this->email;