How to use sometimes rule in Laravel 5 request class

后端 未结 4 503
南笙
南笙 2021-02-12 10:56

I have the following request class:



        
4条回答
  •  广开言路
    2021-02-12 11:37

    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;
    }
    

提交回复
热议问题