Skip to content

Commit

Permalink
refactor: simplify on deleted logic and check if array key exists
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmeira committed Sep 26, 2023
1 parent 32634b9 commit cd9144d
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/Traits/HasAttachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ public static function bootHasAttachments(): void
$self = new static;

$self::deleted(static function (Model $model) use ($self) {
if (!isset($model->forceDeleting)) {
$self->removeAttachments($model);
} else if ($model->forceDeleting) {
if (!isset($model->forceDeleting) || $model->forceDeleting) {
$self->removeAttachments($model);
}
});
Expand Down Expand Up @@ -131,7 +129,7 @@ protected function mergeAttachments(?array $newAttachments): ?array
$rawAttachments = $this->getRawAttachments();

foreach ($newAttachments as $key => $path) {
if (!empty($rawAttachments[$key])) {
if (Arr::exists($rawAttachments, $key)) {
$this->deleteAttachment($key);
}
}
Expand Down

0 comments on commit cd9144d

Please sign in to comment.