Browse Source

表单功能优化

jqh 4 years ago
parent
commit
cebc2753ab
4 changed files with 18 additions and 17 deletions
  1. 1 1
      src/Form/Field.php
  2. 6 6
      src/Form/Field/UploadField.php
  3. 0 5
      src/Http/Repositories/Extension.php
  4. 11 5
      src/Widgets/Form.php

+ 1 - 1
src/Form/Field.php

@@ -421,7 +421,7 @@ class Field implements Renderable
     }
 
     /**
-     * @return Fluent
+     * @return Fluent|\Illuminate\Database\Eloquent\Model
      */
     public function values()
     {

+ 6 - 6
src/Form/Field/UploadField.php

@@ -130,10 +130,10 @@ trait UploadField
         }
 
         if ($this->name instanceof \Closure) {
-            return $this->name->call($this, $file);
+            $this->name = $this->name->call($this->values(), $file);
         }
 
-        if (is_string($this->name)) {
+        if ($this->name !== '' && is_string($this->name)) {
             return $this->name;
         }
 
@@ -148,7 +148,7 @@ trait UploadField
     public function getDirectory()
     {
         if ($this->directory instanceof \Closure) {
-            return call_user_func($this->directory, $this->form);
+            $this->directory = $this->directory->call($this->values(), $this->form);
         }
 
         return $this->directory ?: $this->defaultDirectory();
@@ -230,8 +230,8 @@ trait UploadField
     /**
      * Specify the directory and name for upload file.
      *
-     * @param string      $directory
-     * @param null|string $name
+     * @param string|\Closure $directory
+     * @param null|string     $name
      *
      * @return $this
      */
@@ -247,7 +247,7 @@ trait UploadField
     /**
      * Specify the directory upload file.
      *
-     * @param string $dir
+     * @param string|\Closure $dir
      *
      * @return $this
      */

+ 0 - 5
src/Http/Repositories/Extension.php

@@ -19,9 +19,6 @@ class Extension extends Repository
         }
 
         return $data;
-        //return collect($data)->sort(function ($row) {
-        //    return ! empty($row['version']) && empty($row['new_version']);
-        //})->toArray();
     }
 
     /**
@@ -60,8 +57,6 @@ class Extension extends Repository
 
     public function update(Form $form)
     {
-        $id = $form->getKey();
-
         return true;
     }
 

+ 11 - 5
src/Widgets/Form.php

@@ -312,9 +312,7 @@ class Form implements Renderable
     }
 
     /**
-     * @param array|Arrayable|Closure $data
-     *
-     * @return Fluent
+     * @return Fluent|\Illuminate\Database\Eloquent\Model
      */
     public function data()
     {
@@ -332,13 +330,21 @@ class Form implements Renderable
      */
     public function fill($data)
     {
-        $this->data = new Fluent(Helper::array($data));
+        if ($data instanceof \Closure) {
+            $data = $data($this);
+        }
+
+        if (is_array($data)) {
+            $this->data = new Fluent($data);
+        } elseif ($data instanceof Arrayable) {
+            $this->data = $data;
+        }
 
         return $this;
     }
 
     /**
-     * @return Fluent
+     * @return Fluent|\Illuminate\Database\Eloquent\Model
      */
     public function model()
     {