Joel James
Joel James

Reputation: 1345

Laravel validation required rule not working

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

Upvotes: 0

Views: 4906

Answers (1)

Joel James
Joel James

Reputation: 1345

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'

Upvotes: 2

Related Questions