Skip to content

Commit f761005

Browse files
committed
Update RecordController update
1 parent d41805d commit f761005

File tree

3 files changed

+42
-32
lines changed

3 files changed

+42
-32
lines changed

publishable/assets/js/app.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10342,13 +10342,16 @@ __webpack_require__.r(__webpack_exports__);
1034210342
field: field
1034310343
}
1034410344
}).then(function (res) {
10345-
// console.log(res.data);
10345+
console.log(res.data);
10346+
1034610347
if (res.data.success == true) {
1034710348
toastr.success("Relation Deleted Successfully");
1034810349

1034910350
_this4.fetchDatabaseTables();
1035010351
}
1035110352
})["catch"](function (err) {
10353+
console.log(err);
10354+
1035210355
_this4.displayError(err.response);
1035310356
});
1035410357
} else if (result.dismiss === Swal.DismissReason.cancel) {

resources/assets/js/views/crud/CrudFields.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,14 @@
303303
}
304304
})
305305
.then(res => {
306-
// console.log(res.data);
306+
console.log(res.data);
307307
if( res.data.success == true ){
308308
toastr.success("Relation Deleted Successfully");
309309
this.fetchDatabaseTables();
310310
}
311311
})
312312
.catch(err => {
313+
console.log(err);
313314
this.displayError(err.response);
314315
});
315316

src/Http/Controllers/RecordController.php

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -86,62 +86,68 @@ public function update(Request $request)
8686
return $response;
8787
}
8888

89-
$tableName = $request->table;
90-
$originalColumns = Table::getColumnsName($tableName);
91-
$columns = json_decode($request->columns);
92-
$fields = json_decode($request->fields);
89+
$tableName = $request->table;
90+
$columns = json_decode($request->columns);
91+
$fields = json_decode($request->fields);
9392

9493
$errors = $this->validation($fields, $columns, 'update');
9594

9695
if (count($errors) > 0) {
9796
return $this->generateError($errors);
9897
}
9998

100-
$object = DBM::Object()->where('name', $tableName)->first();
101-
$model = $object->model;
102-
$details = $object->details;
103-
$key = $details['findColumn'];
99+
$object = DBM::Object()->where('name', $tableName)->first();
104100

105-
if (!class_exists($model)) {
101+
if (!class_exists($object->model)) {
106102
return $this->generateError(["Model not found. Please create model first"]);
107103
}
108104

109105
try {
106+
$this->updateData($request, $object);
107+
return response()->json(['success' => true]);
108+
} catch (\Exception $e) {
109+
return $this->generateError([$e->getMessage()]);
110+
}
111+
}
110112

111-
$table = DBM::model($model, $tableName)->where($key, $columns->{$key})->first();
113+
return response()->json(['success' => false]);
114+
}
112115

113-
foreach ($columns as $column => $value) {
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'];
114123

115-
if (in_array($column, $originalColumns)) {
124+
$table = DBM::model($object->model, $tableName)->where($key, $columns->{$key})->first();
116125

117-
if ($request->hasFile($column)) {
118-
$value = $this->saveFiles($request, $column, $tableName);
119-
}
126+
foreach ($columns as $column => $value) {
120127

121-
if ($value !== null && $value !== "") {
128+
if (in_array($column, $originalColumns)) {
122129

123-
if (!Driver::isMongoDB()) {
124-
if ($functionName = $this->hasFunction($fields, $column)) {
125-
$value = $this->executeFunction($functionName, $value);
126-
}
127-
}
130+
if ($request->hasFile($column)) {
131+
$value = $this->saveFiles($request, $column, $tableName);
132+
}
128133

129-
$table->{$column} = $this->prepareStoreField($value, $tableName, $column);
134+
if ($value !== null && $value !== "") {
135+
136+
if (!Driver::isMongoDB()) {
137+
if ($functionName = $this->hasFunction($fields, $column)) {
138+
$value = $this->executeFunction($functionName, $value);
130139
}
131140
}
132-
}
133141

134-
if ($table->update()) {
135-
$this->updateRelationshipData($fields, $columns, $object, $table);
136-
return response()->json(['success' => true]);
142+
$table->{$column} = $this->prepareStoreField($value, $tableName, $column);
137143
}
138-
139-
} catch (\Exception $e) {
140-
return $this->generateError([$e->getMessage()]);
141144
}
142145
}
143146

144-
return response()->json(['success' => false]);
147+
if ($table->update()) {
148+
$this->updateRelationshipData($fields, $columns, $object, $table);
149+
return response()->json(['success' => true]);
150+
}
145151
}
146152

147153
public function delete(Request $request)

0 commit comments

Comments
 (0)