Fix JSON
This commit is contained in:
parent
0456eeb339
commit
b9851a2c69
|
@ -82,12 +82,19 @@ class Validator
|
||||||
|
|
||||||
public function json($code = 400, $data = [])
|
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([
|
$data = array_merge([
|
||||||
'message' => 'Please check your input',
|
'message' => 'Please check your input',
|
||||||
'error' => 'validator.form-error',
|
'error' => 'validator.form-error',
|
||||||
'errors' => array_map(function ($errors) {
|
'errors' => $errors
|
||||||
return "validator.".$errors[0].(!is_null($this->context) ? ':'.$this->context : '');
|
|
||||||
}, $this->errors)
|
|
||||||
], $data);
|
], $data);
|
||||||
|
|
||||||
return new JsonResponse($data, $code);
|
return new JsonResponse($data, $code);
|
||||||
|
|
Loading…
Reference in New Issue