This commit is contained in:
Maxime Renou 2019-03-01 11:39:19 +01:00
parent 0456eeb339
commit b9851a2c69
1 changed files with 10 additions and 3 deletions

View File

@ -82,12 +82,19 @@ class Validator
public function json($code = 400, $data = [])
{
$errors = [];
foreach ($this->errors as $field => $error)
{
$errors[$field] = [
'error' => "validator.".$errors[0].(!is_null($this->context) ? ':'.$this->context : '')
];
}
$data = array_merge([
'message' => 'Please check your input',
'error' => 'validator.form-error',
'errors' => array_map(function ($errors) {
return "validator.".$errors[0].(!is_null($this->context) ? ':'.$this->context : '');
}, $this->errors)
'errors' => $errors
], $data);
return new JsonResponse($data, $code);