S
S
suhuxa12017-08-02 21:36:29
Laravel
suhuxa1, 2017-08-02 21:36:29

How to force laravel validate to validate a field only if it is not empty?

There is a field to which I gave validation parameters: url | max:40 . The field is optional and may be empty. But in this case, I constantly get an error that the field does not fit the url format. Well, it's clear, it's empty. So how to explain to Lara that validation should be done only if the field is filled?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
D3lphi, 2017-08-02
@suhuxa1

Add sometimes and nullable rules.
sometimes|nullable|url|max:40

A
Alexander Pushkarev, 2017-08-02
@AXP-dev

So have you tried it?
url | min:0 | max:40

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question