From a5a8105c1eda8ffa46fc33da69d3133c3e056e45 Mon Sep 17 00:00:00 2001 From: loganfox Date: Thu, 28 Mar 2024 10:12:06 -0500 Subject: [PATCH] Update original email --- src/Listeners/SendSecurityNotification.php | 2 +- src/Traits/Securable.php | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Listeners/SendSecurityNotification.php b/src/Listeners/SendSecurityNotification.php index a853ce0..f0482aa 100644 --- a/src/Listeners/SendSecurityNotification.php +++ b/src/Listeners/SendSecurityNotification.php @@ -15,7 +15,7 @@ public function handle(SecureFieldsUpdated $event): void { $notificationClass = config('security-notifications.notifications.secure_fields'); - Notification::route('mail', $event->model->getSecurityNotificationsEmail()) + Notification::route('mail', $event->model->original_email) ->notify(new $notificationClass($event->fields)); } } diff --git a/src/Traits/Securable.php b/src/Traits/Securable.php index 35172fa..e683d88 100644 --- a/src/Traits/Securable.php +++ b/src/Traits/Securable.php @@ -15,17 +15,14 @@ trait Securable 'password', ]; - public function getSecurityNotificationsEmail(): string - { - return $this->getOriginal('email'); - } - public static function bootSecurable(): void { if (config('security-notifications.send_notifications')) { static::updated(function (Model $model) { $changedSecureFields = collect($model->getChanges())->only(self::$secureFields); + $model->setAttribute('original_email', $model->getOriginal('email') ?? $model->getAttribute('email')); + if ($changedSecureFields->count()) { event(new SecureFieldsUpdated($model, $changedSecureFields->toArray())); }