-
-
Notifications
You must be signed in to change notification settings - Fork 210
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
Conflict Between Optional and Required Rules #844
Comments
This should be fixed with the release later today |
Thank you, @rubenvanassche, but this doesn't fully solve the problem for me. For example: it('this test should not create an error during validation', function () {
class UpdateProductData extends Data
{
public function __construct(
#[RequiredWith('discountValue')]
public DiscountType $discountType = new Optional,
#[RequiredWith('discountType')]
public float $discountValue = new Optional,
) {
}
}
dd(UpdateProductData::validateAndCreate([]));
}); This code currently throws an error, but it shouldn't, because neither |
I cannot reproduce that, you know you're missing the optional type in the properties? |
Sorry @rubenvanassche, my example was wrong! Here is a correct example: it('this test should not create an error during validation', function () {
class UpdateProductData extends Data
{
public function __construct(
public string|Optional $type = new Optional,
#[RequiredUnless('type', 'bundle')]
public float|null|Optional $price = new Optional,
) {
}
}
UpdateProductData::validateAndCreate([]);
}); This code currently throws an error, but it shouldn't, because neither |
✏️ Describe the bug
Optional
should be skipped when aRequired
rule is applied (e.g.,RequireWith
,RequiredIf
).↪️ To Reproduce
✅ Expected behavior
In this test, I expect an error message like 'The discountType is required when discountValue is present.', because
discountValue
is provided butdiscountType
is not.The issue arises due to two points:
RequiredWith
,RequiredIf
, etc.SometimesRuleInferrer
should not add thesometimes
rule when the attribute has rules likeRequiredWith
,RequiredIf
, etc.🖥️ Versions
Laravel: 11
Laravel Data: 4.8.1
PHP: 8.2
I can try to make a PR if you think this is an issue.
The text was updated successfully, but these errors were encountered: