Skip to content

Commit

Permalink
fix: don't delete and recreate existing mediables and fileables
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofandel committed Apr 1, 2024
1 parent 8611299 commit ae1bc39
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
6 changes: 1 addition & 5 deletions src/Repositories/Behaviors/HandleFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ public function afterSaveHandleFiles($object, $fields)
return;
}

$object->files()->sync([]);

$this->getFiles($fields)->each(function ($file) use ($object) {
$object->files()->attach($file['id'], Arr::except($file, ['id']));
});
$object->files()->sync($this->getFiles($fields)->map(fn ($file) => Arr::except($file, ['id']) + ['file_id' => $file['id']]));
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/Repositories/Behaviors/HandleMedias.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ public function afterSaveHandleMedias($object, $fields)
return;
}

$object->medias()->sync([]);

$this->getMedias($fields)->each(function ($media) use ($object) {
$object->medias()->attach($media['id'], Arr::except($media, ['id']));
});
$object->medias()->sync($this->getMedias($fields)->map(fn ($media) => Arr::except($media, ['id']) + ['media_id' => $media['id']]));
}

/**
Expand Down

0 comments on commit ae1bc39

Please sign in to comment.