I wanted to know that what will be happen if validation fail in laravel, means that the rest of code will be execute or not. I have following code in store method
$this->validate($request, [
'name' => 'required|min:3',
'email' => 'required|email',
'message' => 'required',
]);
return response()->json([
'success' => 'Your email has been sent successfully.'
]);
I have checked with $validator->fails())
but it does not return the error message which i added in the if statement.
if($validator->fails()) {
return response()->json([
'error' => 'There are some errors.'
]);
}else{
return response()->json([
'success' => 'Your email has been sent successfully.'
]);
}
Can anyone guide me about my question, i would like to appreciate. Thank You
No an exception will be thrown in your case upon validation fails. According to laravel official doc:
then the client side: