]> BookStack Code Mirror - bookstack/blobdiff - app/Entities/Repos/BaseRepo.php
Guest create page: name field autofocus
[bookstack] / app / Entities / Repos / BaseRepo.php
index cfde7fe1c578eb6876b1e77237c86e74bb584493..815c0bb2ec503522ec9962f959e60e5fad079292 100644 (file)
@@ -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();
         }