Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Add ability to validate one of multiple date formats #39170

Merged
merged 2 commits into from
Oct 13, 2021
Merged

[8.x] Add ability to validate one of multiple date formats #39170

merged 2 commits into from
Oct 13, 2021

Conversation

stevebauman
Copy link
Contributor

Description

This PR adds the ability to provide multiple possible date formats to the date_format validation rule, allowing developers to use one request input for multiple possible date format types.

This PR validates that the input must match one of the possible formats.

Use Case

I'm working on a system where a user can enter a date with a year, or without a year, to signify whether that date is recurring. The formats I'm requiring are Y-m-d (one time) or m-d (recurring).

Currently, I have to create my own validation rule, or use multiple inputs to handle the alternate date formats:

public function rules()
{
    return [
        'date_one_time'  => 'date_format:Y-m-d',
        'date_recurring' => 'date_format:m-d',
    ];
}

This can be simplified with this PR:

public function rules()
{
    return [
        'date' => 'date_format:Y-m-d,m-d',
    ];
}

Thanks so much for your time -- no hard feelings on closure! ❤️

@taylorotwell taylorotwell merged commit 2bad6a3 into laravel:8.x Oct 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants