From 27e418b5108d69322e6ea05b9cec02f138e08352 Mon Sep 17 00:00:00 2001 From: loganfox Date: Mon, 14 Oct 2024 10:38:45 -0500 Subject: [PATCH] Extract to method to allow override --- src/Traits/Securable.php | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) 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;