2017-12-18 255 views

回答

4

您可以覆盖getValidatorInstance()方法在自定义请求类是这样的:

protected function getValidatorInstance() 
{ 
    $validator = parent::getValidatorInstance(); 

    // here you can apply hook (example hook taken from documentation): 

    $validator->after(function ($validator) { 
     if ($this->somethingElseIsInvalid()) { 
      $validator->errors()->add('field', 'Something is wrong with this field!'); 
     } 
    }); 

    return $validator; 
}