I am working on online examination system on laravel when users get exam I want to receive some data from API and store in a database. Data will be something like this.
{
"user_id": [
"420"
],
"test_id": [
"12"
],
"question_id": [
"1",
"2",
"3",
"4"
]
}
My Controller
$fbres = new Testapp;
$json = $request->all();
$data = $json;
$user_id = $request->user_id;
$question_id = $request->question_id;
$test_id = $request->test_id;
foreach ($data as $key)
{
$user_id = $key['user_id'];
$test_id = $key['test_id'];
$question_id = $key['question_id'];
$data1 = array(
array('user_id'=> $user_id, 'question_id'=> $question_id, 'test_id'=> $test_id)
);
$fbres::insert($data1);
}