Skip to content

Commit

Permalink
Extract to method to allow override
Browse files Browse the repository at this point in the history
  • Loading branch information
LoganTFox committed Oct 14, 2024
1 parent ec163d5 commit 27e418b
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/Traits/Securable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 27e418b

Please sign in to comment.