Laravel validation required rule not working

痴心易碎 提交于 2019-12-12 02:27:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!