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 default rules in conditional rules #38450

Merged
merged 2 commits into from
Aug 19, 2021
Merged

[8.x] Add default rules in conditional rules #38450

merged 2 commits into from
Aug 19, 2021

Conversation

bastien-phi
Copy link
Contributor

PR #38361 introduced ConditionalRules to conditionally add rules to the validation.

Imagine a validation like :

public function rules()
{
    return [
        'email' => [
            Rule::when($this->someComplexTest(), ['required']),
            Rule::when(!$this->someComplexTest(), ['nullable']),
        ]
    ];
}

This PR adds the ability to define the behaviour when the condition is false.

public function rules()
{
    return [
        'email' => [
            Rule::when($this->someComplexTest(), ['required'], ['nullable']),
        ]
    ];
}

This behavior already exists in collections, conditionable, ...

@bastien-phi bastien-phi changed the title Add default rules in conditional rules [8.x] Add default rules in conditional rules Aug 19, 2021
@taylorotwell taylorotwell merged commit eb70335 into laravel:8.x Aug 19, 2021
@bastien-phi
Copy link
Contributor Author

Thanks !

@bastien-phi bastien-phi deleted the add_default_on_conditional_rules branch August 20, 2021 09:15
Krisell pushed a commit to Krisell/framework that referenced this pull request Aug 20, 2021
* Add default rules in conditional rules

* formatting

Co-authored-by: Taylor Otwell <taylorotwell@gmail.com>
Krisell pushed a commit to Krisell/framework that referenced this pull request Aug 20, 2021
* Add default rules in conditional rules

* formatting

Co-authored-by: Taylor Otwell <taylorotwell@gmail.com>
victorvilella pushed a commit to cdsistemas/framework that referenced this pull request Oct 12, 2021
* Add default rules in conditional rules

* formatting

Co-authored-by: Taylor Otwell <taylorotwell@gmail.com>
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.

None yet

3 participants