I am working on updating data in API endpoint. As, I am using Form Request Validation to keep the validation separate from Controller.
That works fine with the Store Request.
But, when I am trying to update a single data as mentioned below, the response is returning the following response data.
As, the data are already stored in database. When I send request for updating data.. that should return the updated data. But, It's not returning.
Need help to solve that.
JSON Data in Body:
{
"title": "Question Changed 2"
}
Current Response:
{
"question_type": [
"Question Type is Required!"
],
"question": [
"Question is Required!"
],
"is_required": [
"Is Require Value is Required"
]
}
QuestionRequest:
public function rules()
{
return [
'question_type' => 'required | min:3 | max:10',
'title' => 'required | min:5 | max:100',
'question' => 'required | min:5 | max:255',
'description' => 'min:10 | max:255',
'is_required' => 'required',
];
}
Update:
public function update(QuestionRequest $request, Question $question)
{
$question = $question->update($request->all());
return response()->json($question, 200);
}
updatereturns a boolean