Thank you very much if you wouldn't mind I have one more part of the function that is an array already that I am trying to update
New controller code:
public function saveEdit(Request $request)
{
try {
$unsanitizedData = $request->all();
$data = [];
$fid = $unsanitizedData['formId'];
$data['form_name'] = $unsanitizedData['cred']['name'];
$data['org'] = $unsanitizedData['cred']['organization'];
$data['updated_by'] = $unsanitizedData['updatedBy'];
$data['user_id'] = $unsanitizedData['id'];
$data['activated'] = $unsanitizedData['cred']['activated'];
$data['type'] = $unsanitizedData['cred']['inputs']['type'];
$data['name'] = $unsanitizedData['cred']['inputs']['name'];
foreach ($unsanitizedData as $st) {
$form = admin_form::where('id', '49')->update([
'form_name'=> $data['form_name'],
'org'=> $data['org'],
'updated_by' => $data['updated_by'],
'user_id' => $data['user_id'],
'activated' => $data['activated']
]);
}
$input['form_id'] = $form->id;
foreach ($unsanitizedData['cred']['inputs'] as $input) {
admin_form_fields::where('form_id', $fid)->update([
'type' => $data['type'],
'name' => $data['name']
]);
}
$res['status'] = true;
$res['message'] = 'Success';
return response($res, 200);
} catch (\Illuminate\Database\QueryException $ex) {
$res['status'] = false;
$res['message'] = $ex->getMessage();
return response($res, 500);
}
}
this is what the data strucute being sent to the API looks like
{cred: {name: "Test namegghh", organization: "Test Orggghhh", activated: [0],…}, formId: "49", id: 29,…}
cred: {name: "Test namegghh", organization: "Test Orggghhh", activated: [0],…}
activated: [0]
inputs: [{type: "email", name: "Filehh"}]
0: {type: "email", name: "Filehh"}
name: "Test namegghh"
organization: "Test Orggghhh"
formId: "49"
id: 29
updatedBy: "test"
The inputs is an array of inputs with a name and type eg: type: file, name: CV a form can have as many inputs as it wants ive tryed to apply the same logic as the other statement but I am getting an undefined index type and name error do you know how I could get around this is it because its nested? thank you very much for your help