I am building a RESTful API with Laravel 5.1 - When a post request is made, I validate the input, if the input is not valid, I throw an exception.
Current Response Sample:
{
"message": "{\"email\":[\"The email field is required.\"]}",
"status_code": 400
}
How to make my response look like this:
{
"message": {
"email": "The email field is required."
},
"status_code": 400
}
Here's how I throw the exception:
$validator = Validator::make($this->request->all(), $this->rules());
if ($validator->fails()) {
throw new ValidationFailedException($validator->errors());
}