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 prohibited_with and prohibited_without validation rules #37086

Conversation

menthol
Copy link

@menthol menthol commented Apr 22, 2021

Now that #36516 and #36667 are merged, I would like to add the missing rules to have same ruleset that the required ones.

This PR add :

  • prohibited_with: Validate that this attribute does not exist when any indicated attribute exists.
  • prohibited_with_all: Validate that this attribute does not exist when all indicated attributes exist.
  • prohibited_without: Validate that this attribute does not exist when indicated attribute does not exist.
  • prohibited_without_all: Validate that this attribute does not exist when all indicated attributes do not exist.

Example from the application I am currently working on:

Validator::validate([
    'start_date' => '2021-01', 
    'end_date' => '2021-03',
    'duration' => 'quarter'
], [
    'start_date' => ['date_format:Y-m', 'required_with:end_date'],
    'end_date' => [
        'date_format:Y-m',
        'prohibited_with:duration',
        'prohibited_without:start_date',
        'after_or_equal:options.start',
    ],
    'duration' => ['sometimes', 'in:month,quarter,custom'],
]);

@menthol menthol force-pushed the feature/add-missing-prohibided-validation-rules branch from 6e8619a to 1566c11 Compare April 22, 2021 14:18
@GrahamCampbell GrahamCampbell changed the title Add prohibited_with and prohibited_without validation rules [8.x] Add prohibited_with and prohibited_without validation rules Apr 22, 2021
@taylorotwell
Copy link
Member

I don't know - I feel like we are kinda bloating the validator with some of this. If an attribute shouldn't be around when another attribute is present - just ignore it?

@menthol menthol deleted the feature/add-missing-prohibided-validation-rules branch April 28, 2021 07:34
@mreduar
Copy link

mreduar commented Sep 30, 2021

Maybe this could be solved if we create a Rule::prohibitedIf() method?

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