-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[11.x] Conditional Validation for Fluent Email Rules #54255
base: 11.x
Are you sure you want to change the base?
[11.x] Conditional Validation for Fluent Email Rules #54255
Conversation
if (value($this->rfcCompliant, $attribute, $value)) { | ||
$rules[] = 'rfc'; | ||
} | ||
|
||
if ($this->strictRfcCompliant) { | ||
if (value($this->strictRfcCompliant, $attribute, $value)) { | ||
$rules[] = 'strict'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Furthermore, it would be interesting, yet not easily implemented with the current implementation, if the method didn't only return whether to apply a specific rule but also if the more general rule should be applied with a flag (in this case strict
). Implementing this by making the first param of the setter function bool|\Closure(): bool
as well, would be one option, only passing in bool|Closure(): RfcComplianceEnum|null $condition
another.
Our hypothetical RfcComplianceEnum
would look something like this:
enum RfcComplianceEnum
{
case Loose; // or Basic
case Strict;
}
Add Conditional Validation for Fluent Email Rules
This PR enhances the
Email
validation rule in Laravel by introducing conditional validation capabilities. It allows developers to dynamically enable or disable specific email validation rules, making the validation logic more flexible and adaptable to specific use cases.Key Features:
Email::default()
rules, such as disabling MX record validation for certain routes. This is particularly useful for cases like Single Sign-On (SSO) emails without inboxes.Key Changes:
Email
class to acceptbool|Closure
conditions for rules likerfcCompliant
,validateMxRecord
,preventSpoofing
, andwithNativeValidation
.buildValidationRules
method to evaluate conditions dynamically based on the provided attribute and value.ValidationEmailRuleTest
to ensure the new functionality works as intended for various scenarios.Benefits:
This update aligns with Laravel's focus on making validation rules expressive and adaptable while maintaining backward compatibility.