feat(attachment): implement deletion of cropped attachments alongside original and update README
This commit is contained in:
@@ -108,13 +108,23 @@ class AttachmentService
|
||||
|
||||
public function delete(Attachment $attachment): void
|
||||
{
|
||||
$deleted = Storage::disk('s3')->delete($attachment->path);
|
||||
$croppedAttachment = $attachment->croppedAttachment;
|
||||
$paths = array_values(array_filter([
|
||||
$attachment->path,
|
||||
$croppedAttachment?->path,
|
||||
]));
|
||||
$deleted = Storage::disk('s3')->delete(
|
||||
count($paths) === 1 ? $paths[0] : $paths
|
||||
);
|
||||
|
||||
if (! $deleted) {
|
||||
throw new AttachmentStorageException('No se pudo eliminar el archivo del disco s3.');
|
||||
throw new AttachmentStorageException('No se pudieron eliminar los archivos del disco s3.');
|
||||
}
|
||||
|
||||
$attachment->delete();
|
||||
DB::transaction(function () use ($attachment, $croppedAttachment): void {
|
||||
$attachment->delete();
|
||||
$croppedAttachment?->delete();
|
||||
});
|
||||
}
|
||||
|
||||
public function copy(Attachment $source, string $path): Attachment
|
||||
|
||||
Reference in New Issue
Block a user