Home > other >  All bosses Laravel Validate how to make the form have failed to stop the other attributes of verific
All bosses Laravel Validate how to make the form have failed to stop the other attributes of verific

Time:01-19



If inscribe!
Laravel Validate how to make the form hit the first authentication failed to stop continue to verify the other attributes?
Warm prompt: this is a property not bail no longer verify other rules.



Laravel
Validate


CodePudding user response:


I also encountered the same doubts, is solved, please?

CodePudding user response:


No problem, please look here q&a: help bosses rules have multiple attributes (), how to meet a fail over other properties test...
Can only put the time-consuming validation rules not in form validation, but through the form validation and then judge for themselves.

CodePudding user response:

@ Configurable
Public class ValidatorConfig {
@ Bean
Public the Validator Validator () {
ValidatorFactory ValidatorFactory=Validation. ByProvider (HibernateValidator. Class)
The configure ()
FailFast (true)
BuildValidatorFactory ();
The Validator Validator=validatorFactory. GetValidator ();
Return the validator.
}
}


Need to return to the unified format, abnormal configuration interceptors, listening BindException
@ ExceptionHandler (value=https://bbs.csdn.net/topics/BindException.class)
@ ResponseBody
Public Result<?> BindErrorHandler (Exception e) throws the Exception {
BindException BindException=(BindException) e;
List FieldErrorList=bindException. GetFieldErrors ();
if(null !=fieldErrorList & amp; & FieldErrorList. The size () & gt; 0 {
FieldError FieldError=fieldErrorList. Get (0);
String message=fieldError. GetDefaultMessage ();
Return the Result. The error (message);
}
Return the Result. The error (SysDefaultErr. SYSTEM_ERROR);
}
  • Related