Answer the question
In order to leave comments, you need to log in
How to display validation errors with AJAX?
Like this, I pass in the form of an error, without ajax, it works.
public function login(Request $request) {
$messages = [
'email.required' => 'Заполните поле',
'email.email' => 'Вы ввели не email'
];
$validator = Validator::make($request->all(), [
'email' => 'required|string|email|max:255',
], $messages);
if ($validator->fails()) {
return Redirect::back()->withErrors($validator);
}
}
$messages = [
'email.required' => 'Заполните поле',
'email.email' => 'Вы ввели не email',
'password.required' => 'Введите пароль',
'password.min' => 'Пароль слишком короткий (миниум 8 символов)',
];
$validator = Validator::make($request->all(), [
'email' => 'required|string|email|max:255',
'password' => 'required|min:8',
], $messages);
if ($validator->fails()) {
//return Redirect::back()->withErrors($validator); //без аякса
return response()->json($validator->errors());
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question