laradocs 3 éve
szülő
commit
5e06dc7e7b
1 módosított fájl, 12 hozzáadás és 3 törlés
  1. 12 3
      src/Form/Field/UploadField.php

+ 12 - 3
src/Form/Field/UploadField.php

@@ -98,10 +98,8 @@ trait UploadField
      */
     public function renameIfExists(UploadedFile $file)
     {
-        if ($this->getStorage()->exists("{$this->getDirectory()}/$this->name") && ! $this->options['override']) {
+        if ($this->getStorage()->exists("{$this->getDirectory()}/$this->name")) {
             $this->name = $this->generateUniqueName($file);
-        } else {
-            $this->getStorage()->delete("{$this->getDirectory()}/$this->name");
         }
     }
 
@@ -196,6 +194,10 @@ trait UploadField
 
         $this->name = $this->getStoreName($file);
 
+        if ($this->options['override']) {
+            $this->remove();
+        }
+
         $this->renameIfExists($file);
 
         $this->prepareFile($file);
@@ -218,6 +220,13 @@ trait UploadField
         throw new UploadException(trans('admin.uploader.upload_failed'));
     }
 
+    public function remove()
+    {
+        if ($this->getStorage()->exists("{$this->getDirectory()}/$this->name")) {
+            $this->getStorage()->delete("{$this->getDirectory()}/$this->name");
+        }
+    }
+
     /**
      * @param  UploadedFile  $file
      */