diff --git a/api/app/Http/Requests/AnswerFormRequest.php b/api/app/Http/Requests/AnswerFormRequest.php index d9dec34f..d3bedae9 100644 --- a/api/app/Http/Requests/AnswerFormRequest.php +++ b/api/app/Http/Requests/AnswerFormRequest.php @@ -67,18 +67,15 @@ public function rules() foreach ($selectionFields as $field) { if (isset($data[$field['id']]) && is_array($data[$field['id']])) { $data[$field['id']] = array_map(function ($val) use ($field) { - // Find the option by exact ID match first $tmpop = collect($field[$field['type']]['options'])->first(function ($op) use ($val) { - return $op['id'] === $val || $op['name'] === $val; + return isset($op['id'], $op['name']) && ($op['id'] === $val || $op['name'] === $val); }); - - // Return the original value if no match found return isset($tmpop['name']) ? $tmpop['name'] : $val; }, $data[$field['id']]); } elseif (isset($data[$field['id']])) { // Handle single select values $tmpop = collect($field[$field['type']]['options'])->first(function ($op) use ($field, $data) { - return $op['id'] === $data[$field['id']] || $op['name'] === $data[$field['id']]; + return isset($op['id'], $op['name']) && ($op['id'] === $data[$field['id']] || $op['name'] === $data[$field['id']]); }); $data[$field['id']] = isset($tmpop['name']) ? $tmpop['name'] : $data[$field['id']]; }