X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/e537d0c4e8dbf0c8bf4ac8119e6a8d7a4adf4bfb..refs/pull/3918/head:/app/Entities/Repos/BaseRepo.php diff --git a/app/Entities/Repos/BaseRepo.php b/app/Entities/Repos/BaseRepo.php index cfde7fe1c..815c0bb2e 100644 --- a/app/Entities/Repos/BaseRepo.php +++ b/app/Entities/Repos/BaseRepo.php @@ -56,7 +56,7 @@ class BaseRepo $entity->fill($input); $entity->updated_by = user()->id; - if ($entity->isDirty('name')) { + if ($entity->isDirty('name') || empty($entity->slug)) { $entity->refreshSlug(); } @@ -86,14 +86,15 @@ class BaseRepo public function updateCoverImage($entity, ?UploadedFile $coverImage, bool $removeImage = false) { if ($coverImage) { - $this->imageRepo->destroyImage($entity->cover); - $image = $this->imageRepo->saveNew($coverImage, 'cover_book', $entity->id, 512, 512, true); + $imageType = $entity->coverImageTypeKey(); + $this->imageRepo->destroyImage($entity->cover()->first()); + $image = $this->imageRepo->saveNew($coverImage, $imageType, $entity->id, 512, 512, true); $entity->cover()->associate($image); $entity->save(); } if ($removeImage) { - $this->imageRepo->destroyImage($entity->cover); + $this->imageRepo->destroyImage($entity->cover()->first()); $entity->image_id = 0; $entity->save(); }