Вот как выглядит код валидатора:
Код: Выделить всё
$validator = Validator::make($request->all(),[
'email'=>'required|email|unique:user',
'first_name'=>'required|min:3',
]);
if ($validator->fails())
{
$response = ['errors'=>$validator->errors()];
return $this->r(ResponseFactory::invalid_input_params($response));
}
Код: Выделить всё
{
"code": 400,
"kind": "invalid_input_params",
"status": "error",
"data": {
"errors": {
"email": [
"The email has already been taken."
],
"first_name": [
"The first name field is required."
]
}
}
}
Код: Выделить всё
{
"code": 400,
"kind": "invalid_input_params",
"status": "error",
"data": {
"errors": {
"email": "The email has already been taken.",
"first_name": "The first name field is required."
}
}
}
По умолчанию Laravel выводит массив для каждого поля, даже если в каждом поле есть только ошибка — я пытаюсь преобразовать его в строку и принять только первую ошибку.>
Подробнее здесь: https://stackoverflow.com/questions/764 ... -validator
Мобильная версия