yasmin
yasmin

Reputation: 1

laravel validation doesn't pass my none required fields

I have problem with my laravel valdation

the problem is :

I have two none required fields ( password and birthday )

 public function rules()
    {
        return [
            'name'=>'required',
            'email'=>'required|email|unique:users,email,'.Auth::id(),
            'birthday'=>'date',
            'password'=>'confirmed|min:6',

        ];
    }

I can't pass the birthday and the password if they are empty

the error is

The birthday is not a valid date.
The password must be at least 6 characters.

I did dd(Input::All()) inside the rules function and both fields are empty ( null )

any idea about this problem ? ? ?

Upvotes: 0

Views: 142

Answers (1)

patricus
patricus

Reputation: 62228

You need to add the nullable validation:

return [
    'name'=>'required',
    'email'=>'required|email|unique:users,email,'.Auth::id(),
    'birthday'=>'nullable|date',
    'password'=>'nullable|confirmed|min:6',
];

This will allow your fields to be empty. But if they're not empty, they'll be constrained by the other validation rules (e.g. date).

Upvotes: 4

Related Questions