How to use sometimes rule in Laravel 5 request class

后端 未结 4 842
星月不相逢
星月不相逢 2021-02-12 10:56

I have the following request class:



        
4条回答
  •  爱一瞬间的悲伤
    2021-02-12 11:51

    You can attach a sometimes() rule by overriding the getValidatorInstance() function in your form request:

    protected function getValidatorInstance(){
        $validator = parent::getValidatorInstance();
    
        $validator->sometimes('dob', 'valid_date', function($input)
        {
            return apply_regex($input->dob) === true;
        });
    
        return $validator;
    }
    

提交回复
热议问题