|
@@ -11,6 +11,7 @@ use Dcat\Admin\Form\Concerns;
|
|
|
use Dcat\Admin\Form\Condition;
|
|
|
use Dcat\Admin\Form\Field;
|
|
|
use Dcat\Admin\Form\NestedForm;
|
|
|
+use Dcat\Admin\Support\Helper;
|
|
|
use Dcat\Admin\Traits\HasBuilderEvents;
|
|
|
use Dcat\Admin\Traits\HasFormResponse;
|
|
|
use Dcat\Admin\Widgets\DialogForm;
|
|
@@ -969,10 +970,10 @@ class Form implements Renderable
|
|
|
*/
|
|
|
public function prepareInsert($inserts)
|
|
|
{
|
|
|
- $this->prepareHasOneRelation($inserts);
|
|
|
+ Helper::prepareHasOneRelation($this->builder->fields(), $inserts);
|
|
|
|
|
|
foreach ($inserts as $column => $value) {
|
|
|
- if (is_null($field = $this->getFieldByColumn($column))) {
|
|
|
+ if (is_null($field = $this->field($column))) {
|
|
|
unset($inserts[$column]);
|
|
|
continue;
|
|
|
}
|
|
@@ -989,41 +990,6 @@ class Form implements Renderable
|
|
|
return $prepared;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Is input data is has-one relation.
|
|
|
- *
|
|
|
- * @param array $inserts
|
|
|
- */
|
|
|
- public function prepareHasOneRelation(array &$inserts)
|
|
|
- {
|
|
|
- $relations = [];
|
|
|
- $this->builder->fields()->each(function ($field) use (&$relations) {
|
|
|
- $column = $field->column();
|
|
|
-
|
|
|
- if (is_array($column)) {
|
|
|
- foreach ($column as $v) {
|
|
|
- if (Str::contains($v, '.')) {
|
|
|
- $first = explode('.', $v)[0];
|
|
|
- $relations[$first] = null;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (Str::contains($column, '.')) {
|
|
|
- $first = explode('.', $column)[0];
|
|
|
- $relations[$first] = null;
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- foreach ($relations as $first => $v) {
|
|
|
- if (isset($inserts[$first])) {
|
|
|
- $inserts = array_merge($inserts, Arr::dot([$first => $inserts[$first]]));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Ignore fields to save.
|
|
|
*
|
|
@@ -1101,26 +1067,6 @@ class Form implements Renderable
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Find field object by column.
|
|
|
- *
|
|
|
- * @param $column
|
|
|
- *
|
|
|
- * @return mixed
|
|
|
- */
|
|
|
- protected function getFieldByColumn($column)
|
|
|
- {
|
|
|
- return $this->builder->fields()->first(
|
|
|
- function (Field $field) use ($column) {
|
|
|
- if (is_array($field->column())) {
|
|
|
- return in_array($column, $field->column());
|
|
|
- }
|
|
|
-
|
|
|
- return $field->column() == $column;
|
|
|
- }
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Set original data for each field.
|
|
|
*
|