laradocs %!s(int64=3) %!d(string=hai) anos
pai
achega
9ef2698cce
Modificáronse 2 ficheiros con 7 adicións e 2 borrados
  1. 4 1
      src/Form/Field/File.php
  2. 3 1
      src/Form/Field/UploadField.php

+ 4 - 1
src/Form/Field/File.php

@@ -17,7 +17,10 @@ class File extends Field implements UploadFieldInterface
     /**
      * @var array
      */
-    protected $options = ['events' => []];
+    protected $options = [
+        'events' => [],
+        'override' => false,
+    ];
 
     public function __construct($column, $arguments = [])
     {

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

@@ -98,8 +98,10 @@ trait UploadField
      */
     public function renameIfExists(UploadedFile $file)
     {
-        if ($this->getStorage()->exists("{$this->getDirectory()}/$this->name") && ! ($this->options['override'] ?? false)) {
+        if ($this->getStorage()->exists("{$this->getDirectory()}/$this->name") && ! $this->options['override']) {
             $this->name = $this->generateUniqueName($file);
+        } else {
+            $this->getStorage()->delete("{$this->getDirectory()}/$this->name");
         }
     }