Ad

Laravel Validation Required Rule Not Working

- 1 answer

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

Ad

Answer

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'
Ad
source: stackoverflow.com
Ad