I have a Laravel 8 API application. Below is my example test method in the controller which return status 422 with invalid data JSON response.
public function testInvalid()
{
$arrResponse = [
'success' => false,
'message' => 'message',
'data' => [],
'errors' => ['error'],
'error_code' => 422,
];
return response()->json($arrResponse, 422);
}
the above should return the JSON response in postman:
{
"success": false,
"message": "message",
"data": [],
"errors": [
"error"
],
"error_code": 422
}
But it only works on the local
machine.
When I run same on the server
it returns the Unprocessable entity
HTML page.
But if I update it to 200 OK
response code with the same response format. then it returns JSON response from the server
too.
return response()->json($arrResponse, 200);
all other valid request works fine and returns JSON response from the server
.
Is it something I need to check on Apache web-server configuration?
Note: I tried passing Accept: application/json
and Content-Type: application/json
headers in postman request. still the same.