Skip to content

Commit 0ef3ba5

Browse files
committed
Update RecordController update
1 parent f761005 commit 0ef3ba5

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

src/Http/Controllers/RecordController.php

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function update(Request $request)
103103
}
104104

105105
try {
106-
$this->updateData($request, $object);
106+
$this->sync($request, $object);
107107
return response()->json(['success' => true]);
108108
} catch (\Exception $e) {
109109
return $this->generateError([$e->getMessage()]);
@@ -113,43 +113,6 @@ public function update(Request $request)
113113
return response()->json(['success' => false]);
114114
}
115115

116-
public function updateData($request, $object)
117-
{
118-
$tableName = $request->table;
119-
$originalColumns = Table::getColumnsName($tableName);
120-
$columns = json_decode($request->columns);
121-
$fields = json_decode($request->fields);
122-
$key = $object->details['findColumn'];
123-
124-
$table = DBM::model($object->model, $tableName)->where($key, $columns->{$key})->first();
125-
126-
foreach ($columns as $column => $value) {
127-
128-
if (in_array($column, $originalColumns)) {
129-
130-
if ($request->hasFile($column)) {
131-
$value = $this->saveFiles($request, $column, $tableName);
132-
}
133-
134-
if ($value !== null && $value !== "") {
135-
136-
if (!Driver::isMongoDB()) {
137-
if ($functionName = $this->hasFunction($fields, $column)) {
138-
$value = $this->executeFunction($functionName, $value);
139-
}
140-
}
141-
142-
$table->{$column} = $this->prepareStoreField($value, $tableName, $column);
143-
}
144-
}
145-
}
146-
147-
if ($table->update()) {
148-
$this->updateRelationshipData($fields, $columns, $object, $table);
149-
return response()->json(['success' => true]);
150-
}
151-
}
152-
153116
public function delete(Request $request)
154117
{
155118
if ($request->ajax()) {

src/Traits/RecordTrait.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,43 @@ public function prepareJsonFieldData($records, $fields, $object, $findValue)
127127
];
128128
}
129129

130+
public function sync($request, $object)
131+
{
132+
$tableName = $request->table;
133+
$originalColumns = Table::getColumnsName($tableName);
134+
$columns = json_decode($request->columns);
135+
$fields = json_decode($request->fields);
136+
$key = $object->details['findColumn'];
137+
138+
$table = DBM::model($object->model, $tableName)->where($key, $columns->{$key})->first();
139+
140+
foreach ($columns as $column => $value) {
141+
142+
if (in_array($column, $originalColumns)) {
143+
144+
if ($request->hasFile($column)) {
145+
$value = $this->saveFiles($request, $column, $tableName);
146+
}
147+
148+
if ($value !== null && $value !== "") {
149+
150+
if (!Driver::isMongoDB()) {
151+
if ($functionName = $this->hasFunction($fields, $column)) {
152+
$value = $this->executeFunction($functionName, $value);
153+
}
154+
}
155+
156+
$table->{$column} = $this->prepareStoreField($value, $tableName, $column);
157+
}
158+
}
159+
}
160+
161+
if ($table->update()) {
162+
$this->updateRelationshipData($fields, $columns, $object, $table);
163+
return response()->json(['success' => true]);
164+
}
165+
}
166+
130167
public function getSettingOptions($field)
131168
{
132169
$options = $field->settings['options'];

0 commit comments

Comments
 (0)