Skip to content

Commit

Permalink
Fix problems in update and save if no manual fields are defined in a …
Browse files Browse the repository at this point in the history
…Model.
  • Loading branch information
Max-Hutschenreiter committed Dec 10, 2021
1 parent 5054a88 commit 4646161
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/Http/Controllers/TLAPController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ public function update($models, $id, Request $request)

$input = $request->all();

foreach($model::fields() as $field){
if(array_key_exists($field->name, $input)){
$input[$field->name] = $field->preProcessInput($input[$field->name], $request, $model);
if($model::fields()) {
foreach ($model::fields() as $field) {
if (array_key_exists($field->name, $input)) {
$input[$field->name] = $field->preProcessInput($input[$field->name], $request, $model);
}
}
}

Expand All @@ -84,9 +86,11 @@ public function update($models, $id, Request $request)

$model->update($input);

foreach($model::fields() as $field){
if(array_key_exists($field->name, $input)){
$input[$field->name] = $field->postProcessInput($input[$field->name], $request, $model);
if($model::fields()) {
foreach ($model::fields() as $field) {
if (array_key_exists($field->name, $input)) {
$input[$field->name] = $field->postProcessInput($input[$field->name], $request, $model);
}
}
}

Expand All @@ -110,9 +114,11 @@ public function store($models, Request $request)

$input = $request->all();

foreach($TLAPModel::fields() as $field){
if(array_key_exists($field->name, $input)){
$input[$field->name] = $field->preProcessInput($input[$field->name], $request);
if($TLAPModel::fields()) {
foreach ($TLAPModel::fields() as $field) {
if (array_key_exists($field->name, $input)) {
$input[$field->name] = $field->preProcessInput($input[$field->name], $request);
}
}
}

Expand All @@ -130,9 +136,11 @@ public function store($models, Request $request)

$createdModel = $TLAPModel::create($input);

foreach($createdModel::fields() as $field){
if(array_key_exists($field->name, $input)){
$input[$field->name] = $field->postProcessInput($input[$field->name], $request, $createdModel);
if($createdModel::fields()) {
foreach ($createdModel::fields() as $field) {
if (array_key_exists($field->name, $input)) {
$input[$field->name] = $field->postProcessInput($input[$field->name], $request, $createdModel);
}
}
}

Expand Down

0 comments on commit 4646161

Please sign in to comment.