I tried to save data to the MySQL database and successfully saved data. I want to get JSON data in this formate
{
"response_code":0,
"results":[
{
"question":"Here is my question?",
"correct_answer":"Correct Answer",
"incorrect_answers":[
"wrong_1",
"wrong_2",
"wrong_3"
]
}
]
}
But I am getting my JSON data in this format
{
"response_code":0,
"results":[
{
"question":"Here is my question?",
"correct_answer":"right_ans",
"incorrect_answers_1":"wrong_1",
"incorrect_answers_2":"wrong_2",
"incorrect_answers_3":"wrong_3",
}
]
}
Please suggest to me how can I get my JSON Data in my desired format? If you want more files or information then I will edit my questions.
public function toArray($request)
{
return [
"id"=>$this->id,
"right_ans" =>$this->right_ans,
"incorrect_answers_1" =>$this->wrong_1,
"incorrect_answers_1" =>$this->wrong_2,
"incorrect_answers_1" =>$this->wrong_3,
"created"=>$this->created_at,
];
}
