T
T
Twelfth Doctor2017-08-22 14:29:38
Laravel
Twelfth Doctor, 2017-08-22 14:29:38

Why doesn't the validator allow fields to be left blank?

Hello. I have this validator:

public function rules()
    {
        return [
            'content' =>'required|max:50' ,
            'port' =>'sometimes|numeric|max:5' ,
            'weight' =>'sometimes|numeric|max:5' ,
            'priority'=>'sometimes|numeric|max:2' ,
            'host'=>'required|max:30' ,
            'target'=>'sometimes|url|max:30'
        ];
    }

When the weight (or port, priority) field is not filled, I see errors
The port must be a number.
The priority must be a number.
The target format is invalid.

How can I make these fields not required?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
D3lphi, 2017-08-22
@verdex

Add a nullable rule .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question