我在完成考试后在线考试门户工作我想在数据库中存储结果用户详细信息,所有数据都来自API。
数据看起来像
{
"user_id": "420",
"test_id": "2",
"question_id": [
"12",
"13"
],
"c_ans": [
"a",
"b"
],
"ans": [
"a",
"b"
]
}
我的Question_id数组数据存储成功,但不是c_ans和数组。
我的控制器
$fbres = new Testapp;
$json = $request->all();
$data = $json;
$finalData = array();
$blankArr = array();
//Check for array 1-d or 2-d
if(isset($data["user_id"])){
array_push($blankArr, $data);
}else{
$blankArr = $data;
}
foreach ($blankArr as $key => $value)
{
$usr_id = $value['user_id']['0'];
$test_id = $value['test_id']['0'];
$c_ans = $value['c_ans']['0'];
$ans = $value['ans']['0'];
foreach($value['question_id'] as $k => $v){
$finalData = array('user_id'=> $usr_id, 'question_id'=> $v, 'test_id'=> $test_id,'c_ans' => $c_ans,'ans'=>$ans);
$store= $fbres::insert($finalData);
}
}
if($store)
{
return response([
'Success' => "1",
'Message' => "Result Submitted Successfull..."
]);
}
答案存储qazxsw poi