Skip to content

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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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.

3 participants