问题
I need to add required rule if one field is available. Also need to check if it is an integer and 10 digit. So I added the rule like below.
'id_number' => 'sometimes|required|digits:10|integer'
Validations works only when the field is available. But here required rule is not working. It directly shows integer
error even if the field is empty.
I use Laravel 5.1
回答1:
Finally I figured it!
You need to change the order of required rule to last. It works when I add rule like this,
'id_number' => 'sometimes|digits:10|integer|required'
来源:https://stackoverflow.com/questions/34393134/laravel-validation-required-rule-not-working