0

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 ? ? ?

1 Answer 1

4

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).

Sign up to request clarification or add additional context in comments.

1 Comment

its work fine thank you so much , I always do the same as what in my question but there was no problem and i didnt use nullable before , why now ??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.