peterdickins
1 week ago

Validation required_without and date_format

Posted 1 week ago by peterdickins

I have a form on my page that is for a users job history. They can either select an end date or that it is their present role.

return $attributes = request()->validate([
        'position' => 'required',
        'company' => 'required',
        'start_date' => 'date_format:Y-m|required',
        'end_date' => 'date_format:Y-m|required_without:is_present',
        'is_present' => 'required_without:end_date',
        'description' => 'required',
        'location' => 'required',
    ]);

However when I submit the form with end_date empty, I get the following validation response:

The end date does not match the format Y-m.

Any idea why this is?

Please sign in or create an account to participate in this conversation.