Validator
class Validator implements Validator (View source)
Traits
Properties
protected Translator | $translator | The Translator implementation. |
|
protected Container | $container | The container instance. |
|
protected PresenceVerifierInterface | $presenceVerifier | The Presence Verifier implementation. |
|
protected array | $failedRules | The failed validation rules. |
|
protected array | $excludeAttributes | Attributes that should be excluded from the validated data. |
|
protected MessageBag | $messages | The message bag instance. |
|
protected array | $data | The data under validation. |
|
protected array | $initialRules | The initial rules provided. |
|
protected array | $rules | The rules to be applied to the data. |
|
protected string | $currentRule | The current rule that is validating. |
|
protected array | $implicitAttributes | The array of wildcard attributes with their asterisks expanded. |
|
protected callable|null | $implicitAttributesFormatter | The callback that should be used to format the attribute. |
|
protected array | $distinctValues | The cached data for the "distinct" rule. |
|
protected array | $after | All of the registered "after" callbacks. |
|
array | $customMessages | The array of custom error messages. |
|
array | $fallbackMessages | The array of fallback error messages. |
|
array | $customAttributes | The array of custom attribute names. |
|
array | $customValues | The array of custom displayable values. |
|
protected bool | $stopOnFirstFailure | Indicates if the validator should stop on the first rule failure. |
|
bool | $excludeUnvalidatedArrayKeys | Indicates that unvalidated array keys should be excluded, even if the parent array was validated. |
|
array | $extensions | All of the custom validator extensions. |
|
array | $replacers | All of the custom replacer extensions. |
|
protected string[] | $fileRules | The validation rules that may be applied to files. |
|
protected string[] | $implicitRules | The validation rules that imply the field is required. |
|
protected string[] | $dependentRules | The validation rules which depend on other fields as parameters. |
|
protected string[] | $excludeRules | The validation rules that can exclude an attribute. |
|
protected string[] | $sizeRules | The size related validation rules. |
|
protected string[] | $numericRules | The numeric related validation rules. |
|
protected string[] | $defaultNumericRules | The default numeric related validation rules. |
|
protected string | $dotPlaceholder | The current placeholder for dots in rule keys. |
|
protected ValidationException> | $exception | The exception to throw upon failure. |
|
protected callable|null | $ensureExponentWithinAllowedRangeUsing | The custom callback to determine if an exponent is within allowed range. |
Methods
Replace all place-holders for the accepted_if rule.
Replace all place-holders for the declined_if rule.
Replace all place-holders for the between rule.
Replace all place-holders for the date_format rule.
Replace all place-holders for the decimal rule.
Replace all place-holders for the different rule.
Replace all place-holders for the digits rule.
Replace all place-holders for the digits (between) rule.
Replace all place-holders for the extensions rule.
Replace all place-holders for the min rule.
Replace all place-holders for the min digits rule.
Replace all place-holders for the max rule.
Replace all place-holders for the max digits rule.
Replace all place-holders for the missing_if rule.
Replace all place-holders for the missing_unless rule.
Replace all place-holders for the missing_with rule.
Replace all place-holders for the missing_with_all rule.
Replace all place-holders for the multiple_of rule.
Replace all place-holders for the in rule.
Replace all place-holders for the not_in rule.
Replace all place-holders for the in_array rule.
Replace all place-holders for the required_array_keys rule.
Replace all place-holders for the mimetypes rule.
Replace all place-holders for the mimes rule.
Replace all place-holders for the present_if rule.
Replace all place-holders for the present_unless rule.
Replace all place-holders for the present_with rule.
Replace all place-holders for the present_with_all rule.
Replace all place-holders for the required_with rule.
Replace all place-holders for the required_with_all rule.
Replace all place-holders for the required_without rule.
Replace all place-holders for the required_without_all rule.
Replace all place-holders for the size rule.
Replace all place-holders for the gt rule.
Replace all place-holders for the lt rule.
Replace all place-holders for the gte rule.
Replace all place-holders for the lte rule.
Replace all place-holders for the required_if rule.
Replace all place-holders for the required_if_accepted rule.
Replace all place-holders for the required_if_declined rule.
Replace all place-holders for the required_unless rule.
Replace all place-holders for the prohibited_if rule.
Replace all place-holders for the prohibited_unless rule.
Replace all place-holders for the prohibited_with rule.
Replace all place-holders for the same rule.
Replace all place-holders for the before rule.
Replace all place-holders for the before_or_equal rule.
Replace all place-holders for the after rule.
Replace all place-holders for the after_or_equal rule.
Replace all place-holders for the date_equals rule.
Replace all place-holders for the dimensions rule.
Replace all place-holders for the ends_with rule.
Replace all place-holders for the doesnt_end_with rule.
Replace all place-holders for the starts_with rule.
Replace all place-holders for the doesnt_start_with rule.
Get the validation message for an attribute and rule.
Get the proper inline error message for standard and size rules.
Get the inline message for a rule if it exists.
Get the custom error message from the translator.
Check the given messages for a wildcard key.
Get the proper error message for an attribute and size rule.
Get the data type of the given attribute.
Replace all error message place-holders with actual values.
Get the displayable name of the attribute.
Get the given attribute from the attribute translations.
Get the custom name for an attribute if it exists in the given array.
Replace the :attribute placeholder in the given message.
Replace the :index placeholder in the given message.
Replace the :position placeholder in the given message.
Replace the :index or :position placeholder in the given message.
Get the word for a index or position segment.
Replace the :input placeholder in the given message.
Get the displayable name of the value.
Transform an array of attributes to their displayable form.
Call a custom validator message replacer.
Call a class based validator message replacer.
Validate that an attribute was "accepted".
Validate that an attribute was "accepted" when another attribute has a given value.
Validate that an attribute was "declined".
Validate that an attribute was "declined" when another attribute has a given value.
Validate that an attribute is an active URL.
Get the DNS records for the given hostname.
Validate that an attribute is 7 bit ASCII.
Validate the date is before a given date.
Validate the date is before or equal a given date.
Validate the date is after a given date.
Validate the date is equal or after a given date.
Compare a given date against another using an operator.
Get the date format for an attribute if it has one.
Given two date/time strings, check that one is after the other.
Get a DateTime instance from a string.
Get a DateTime instance from a string with no format.
Validate that an attribute contains only alphabetic characters.
Validate that an attribute contains only alpha-numeric characters, dashes, and underscores.
Validate that an attribute contains only alpha-numeric characters.
Validate that an attribute is an array.
Validate that an attribute is a list.
Validate that an array has all of the given keys.
Validate the size of an attribute is between a set of values.
Validate that an attribute is a boolean.
Validate that an attribute has a matching confirmation.
Validate an attribute contains a list of values.
Validate that the password of the currently authenticated user matches the given value.
Validate that an attribute is a valid date.
Validate that an attribute matches a date format.
Validate that an attribute is equal to another date.
Validate that an attribute has a given number of decimal places.
Validate that an attribute is different from another attribute.
Validate that an attribute has a given number of digits.
Validate that an attribute is between a given number of digits.
Validate the dimensions of an image matches the given values.
Test if the given width and height fail any conditions.
Determine if the given parameters fail a dimension ratio check.
Validate an attribute is unique among other values.
Get the values to distinct between.
Extract the distinct values from the data.
Validate that an attribute is a valid e-mail address.
Validate the existence of an attribute value in a database table.
Get the number of records that exist in storage.
Validate the uniqueness of an attribute value on a given database table.
Get the excluded ID column and value for the unique rule.
Get the extra conditions for a unique rule.
Parse the connection / table for the unique / exists rules.
Get the column name for an exists / unique query.
Guess the database column from the given attribute name.
Get the extra conditions for a unique / exists rule.
Validate the extension of a file upload attribute is in a set of defined extensions.
Validate the given value is a valid file.
Validate the given attribute is filled if it is present.
Validate that an attribute is greater than another attribute.
Validate that an attribute is less than another attribute.
Validate that an attribute is greater than or equal another attribute.
Validate that an attribute is less than or equal another attribute.
Validate that an attribute is lowercase.
Validate that an attribute is uppercase.
Validate that an attribute is a valid HEX color.
Validate the MIME type of a file is an image MIME type.
Validate an attribute is contained within a list of values.
Validate that the values of an attribute are in another attribute.
Validate that an attribute is an integer.
Validate that an attribute is a valid IP.
Validate that an attribute is a valid IPv4.
Validate that an attribute is a valid IPv6.
Validate that an attribute is a valid MAC address.
Validate the attribute is a valid JSON string.
Validate the size of an attribute is less than or equal to a maximum value.
Validate that an attribute has a maximum number of digits.
Validate the guessed extension of a file upload is in a set of file extensions.
Validate the MIME type of a file upload attribute is in a set of MIME types.
Check if PHP uploads are explicitly allowed.
Validate the size of an attribute is greater than or equal to a minimum value.
Validate that an attribute has a minimum number of digits.
Validate that an attribute is missing.
Validate that an attribute is missing when another attribute has a given value.
Validate that an attribute is missing unless another attribute has a given value.
Validate that an attribute is missing when any given attribute is present.
Validate that an attribute is missing when all given attributes are present.
Validate the value of an attribute is a multiple of a given value.
"Indicate" validation should pass if value is null.
Validate an attribute is not contained within a list of values.
Validate that an attribute is numeric.
Validate that an attribute exists even if not filled.
Validate that an attribute is present when another attribute has a given value.
Validate that an attribute is present unless another attribute has a given value.
Validate that an attribute is present when any given attribute is present.
Validate that an attribute is present when all given attributes are present.
Validate that an attribute passes a regular expression check.
Validate that an attribute does not pass a regular expression check.
Validate that a required attribute exists.
Validate that an attribute exists when another attribute has a given value.
Validate that an attribute exists when another attribute was "accepted".
Validate that an attribute exists when another attribute was "declined".
Validate that an attribute does not exist or is an empty string.
Validate that an attribute does not exist when another attribute has a given value.
Validate that an attribute does not exist unless another attribute has a given value.
Validate that other attributes do not exist when this attribute exists.
Indicate that an attribute should be excluded when another attribute has a given value.
Indicate that an attribute should be excluded when another attribute does not have a given value.
Validate that an attribute exists when another attribute does not have a given value.
Indicate that an attribute should be excluded when another attribute presents.
Indicate that an attribute should be excluded when another attribute is missing.
Prepare the values and the other value for validation.
Check if parameter should be converted to boolean.
Convert the given values to boolean if they are string "true" / "false".
Convert the given values to null if they are string "null".
Validate that an attribute exists when any other attribute exists.
Validate that an attribute exists when all other attributes exist.
Validate that an attribute exists when another attribute does not.
Validate that an attribute exists when all other attributes do not.
Determine if any of the given attributes fail the required test.
Determine if all of the given attributes fail the required test.
Validate that two attributes match.
Validate the size of an attribute.
Validate the attribute starts with a given substring.
Validate the attribute does not start with a given substring.
Validate the attribute ends with a given substring.
Validate the attribute does not end with a given substring.
Validate that an attribute is a string.
Validate that an attribute is a valid timezone.
Validate that an attribute is a valid URL.
Validate that an attribute is a valid ULID.
Validate that an attribute is a valid UUID.
Get the size of an attribute.
Check that the given value is a valid file instance.
Determine if a comparison passes between the given values.
Parse named parameters to $key => $value items.
Require a certain number of parameters to be present.
Check if the parameters are of the same type.
Adds the existing rule to the numericRules array if the attribute's value is numeric.
Ensure the exponent is within the allowed range.
Create a new Validator instance.
Parse the data array, converting dots and asterisks.
Replace the placeholders used in data keys.
Replace the placeholders in the given string.
Replace each field parameter dot placeholder with dot.
Add an after validation callback.
Determine if the data passes the validation rules.
Determine if the data fails the validation rules.
Determine if the attribute should be excluded.
Remove the given attribute.
Run the validator's rules against its data.
Run the validator's rules against its data.
Get a validated input container for the validated input.
Get the attributes and values that were validated.
Validate a given attribute against a rule.
Determine if the given rule depends on other fields.
Get the explicit keys from an attribute flattened with dot notation.
Get the primary attribute name.
Replace each field parameter which has an escaped dot with the dot placeholder.
Replace each field parameter which has asterisks with the given keys.
Determine if the attribute is validatable.
Determine if the field is present, or the rule implies required.
Determine if a given rule implies the attribute is required.
Determine if the attribute passes any optional check.
Determine if the attribute fails the nullable check.
Determine if it's a necessary presence validation.
Validate an attribute using a custom rule object.
Check if we should stop further validations on a given attribute.
Add a failed rule and error message to the collection.
Add the given attribute to the list of excluded attributes.
Returns the data which was valid.
Returns the data which was invalid.
Generate an array of all attributes that have messages.
Get the failed validation rules.
Get the message container for the validator.
An alternative more semantic shortcut to the message container.
Get the messages for the instance.
Determine if the given attribute has a rule in the given set.
Get a rule and its parameters for a given attribute.
Get the data under validation.
Get the data under validation.
Set the data under validation.
Get the value of a given attribute.
Set the value of a given attribute.
Get the validation rules.
Get the validation rules with key placeholders removed.
Set the validation rules.
Parse the given rules and merge them into current rules.
Add conditions to a given field based on a Closure.
Instruct the validator to stop validating after the first rule failure.
Register an array of custom validator extensions.
Register an array of custom implicit validator extensions.
Register an array of custom dependent validator extensions.
Register a custom implicit validator extension.
Register a custom dependent validator extension.
Register an array of custom validator message replacers.
Set the custom messages for the validator.
Set the custom attributes on the validator.
Add custom attributes to the validator.
Set the callback that used to format an implicit attribute.
Set the custom values on the validator.
Add the custom values for the validator.
Set the fallback messages for the validator.
Get the Presence Verifier implementation.
Set the Presence Verifier implementation.
Get the exception to throw upon failed validation.
Set the exception to throw upon failed validation.
Ensure exponents are within range using the given callback.
Get the Translator implementation.
Call a custom validator extension.
Call a class based validator extension.
Handle dynamic calls to class methods.
Details
protected string
replaceAcceptedIf(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the accepted_if rule.
protected string
replaceDeclinedIf(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the declined_if rule.
protected string
replaceBetween(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the between rule.
protected string
replaceDateFormat(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the date_format rule.
protected string
replaceDecimal(string $message, string $attribute, string $rule, array<int,int> $parameters)
Replace all place-holders for the decimal rule.
protected string
replaceDifferent(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the different rule.
protected string
replaceDigits(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the digits rule.
protected string
replaceDigitsBetween(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the digits (between) rule.
protected string
replaceExtensions(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the extensions rule.
protected string
replaceMin(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the min rule.
protected string
replaceMinDigits(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the min digits rule.
protected string
replaceMax(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the max rule.
protected string
replaceMaxDigits(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the max digits rule.
protected string
replaceMissingIf(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the missing_if rule.
protected string
replaceMissingUnless(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the missing_unless rule.
protected string
replaceMissingWith(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the missing_with rule.
protected string
replaceMissingWithAll(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the missing_with_all rule.
protected string
replaceMultipleOf(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the multiple_of rule.
protected string
replaceIn(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the in rule.
protected string
replaceNotIn(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the not_in rule.
protected string
replaceInArray(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the in_array rule.
protected string
replaceRequiredArrayKeys(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the required_array_keys rule.
protected string
replaceMimetypes(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the mimetypes rule.
protected string
replaceMimes(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the mimes rule.
protected string
replacePresentIf(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the present_if rule.
protected string
replacePresentUnless(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the present_unless rule.
protected string
replacePresentWith(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the present_with rule.
protected string
replacePresentWithAll(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the present_with_all rule.
protected string
replaceRequiredWith(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the required_with rule.
protected string
replaceRequiredWithAll(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the required_with_all rule.
protected string
replaceRequiredWithout(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the required_without rule.
protected string
replaceRequiredWithoutAll(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the required_without_all rule.
protected string
replaceSize(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the size rule.
protected string
replaceGt(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the gt rule.
protected string
replaceLt(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the lt rule.
protected string
replaceGte(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the gte rule.
protected string
replaceLte(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the lte rule.
protected string
replaceRequiredIf(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the required_if rule.
protected string
replaceRequiredIfAccepted(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the required_if_accepted rule.
string
replaceRequiredIfDeclined(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the required_if_declined rule.
protected string
replaceRequiredUnless(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the required_unless rule.
protected string
replaceProhibitedIf(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the prohibited_if rule.
protected string
replaceProhibitedUnless(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the prohibited_unless rule.
protected string
replaceProhibits(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the prohibited_with rule.
protected string
replaceSame(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the same rule.
protected string
replaceBefore(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the before rule.
protected string
replaceBeforeOrEqual(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the before_or_equal rule.
protected string
replaceAfter(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the after rule.
protected string
replaceAfterOrEqual(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the after_or_equal rule.
protected string
replaceDateEquals(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the date_equals rule.
protected string
replaceDimensions(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the dimensions rule.
protected string
replaceEndsWith(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the ends_with rule.
protected string
replaceDoesntEndWith(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the doesnt_end_with rule.
protected string
replaceStartsWith(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the starts_with rule.
protected string
replaceDoesntStartWith(string $message, string $attribute, string $rule, array<int,string> $parameters)
Replace all place-holders for the doesnt_start_with rule.
protected string
getMessage(string $attribute, string $rule)
Get the validation message for an attribute and rule.
protected string|null
getInlineMessage(string $attribute, string $rule)
Get the proper inline error message for standard and size rules.
protected string|null
getFromLocalArray(string $attribute, string $lowerRule, array|null $source = null)
Get the inline message for a rule if it exists.
protected string
getCustomMessageFromTranslator(array|string $keys)
Get the custom error message from the translator.
protected string
getWildcardCustomMessages(array $messages, string $search, string $default)
Check the given messages for a wildcard key.
protected string
getSizeMessage(string $attribute, string $rule)
Get the proper error message for an attribute and size rule.
protected string
getAttributeType(string $attribute)
Get the data type of the given attribute.
string
makeReplacements(string $message, string $attribute, string $rule, array $parameters)
Replace all error message place-holders with actual values.
string
getDisplayableAttribute(string $attribute)
Get the displayable name of the attribute.
protected string|null
getAttributeFromTranslations(string $name)
Get the given attribute from the attribute translations.
protected string|null
getAttributeFromLocalArray(string $attribute, array|null $source = null)
Get the custom name for an attribute if it exists in the given array.
protected string
replaceAttributePlaceholder(string $message, string $value)
Replace the :attribute placeholder in the given message.
protected string
replaceIndexPlaceholder(string $message, string $attribute)
Replace the :index placeholder in the given message.
protected string
replacePositionPlaceholder(string $message, string $attribute)
Replace the :position placeholder in the given message.
protected string
replaceIndexOrPositionPlaceholder(string $message, string $attribute, string $placeholder, Closure|null $modifier = null)
Replace the :index or :position placeholder in the given message.
protected string
numberToIndexOrPositionWord(int $value)
Get the word for a index or position segment.
protected string
replaceInputPlaceholder(string $message, string $attribute)
Replace the :input placeholder in the given message.
string
getDisplayableValue(string $attribute, mixed $value)
Get the displayable name of the value.
protected array
getAttributeList(array $values)
Transform an array of attributes to their displayable form.
protected string|null
callReplacer(string $message, string $attribute, string $rule, array $parameters, Validator $validator)
Call a custom validator message replacer.
protected string
callClassBasedReplacer(string $callback, string $message, string $attribute, string $rule, array $parameters, Validator $validator)
Call a class based validator message replacer.
bool
validateAccepted(string $attribute, mixed $value)
Validate that an attribute was "accepted".
This validation rule implies the attribute is "required".
bool
validateAcceptedIf(string $attribute, mixed $value, mixed $parameters)
Validate that an attribute was "accepted" when another attribute has a given value.
bool
validateDeclined(string $attribute, mixed $value)
Validate that an attribute was "declined".
This validation rule implies the attribute is "required".
bool
validateDeclinedIf(string $attribute, mixed $value, mixed $parameters)
Validate that an attribute was "declined" when another attribute has a given value.
bool
validateActiveUrl(string $attribute, mixed $value)
Validate that an attribute is an active URL.
protected array|false
getDnsRecords(string $hostname, int $type)
Get the DNS records for the given hostname.
bool
validateAscii(string $attribute, mixed $value)
Validate that an attribute is 7 bit ASCII.
bool
validateBail()
"Break" on first validation fail.
Always returns true, just lets us put "bail" in rules.
bool
validateBefore(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate the date is before a given date.
bool
validateBeforeOrEqual(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate the date is before or equal a given date.
bool
validateAfter(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate the date is after a given date.
bool
validateAfterOrEqual(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate the date is equal or after a given date.
protected bool
compareDates(string $attribute, mixed $value, array<int,int|string> $parameters, string $operator)
Compare a given date against another using an operator.
protected string|null
getDateFormat(string $attribute)
Get the date format for an attribute if it has one.
protected int
getDateTimestamp(mixed $value)
Get the date timestamp.
protected bool
checkDateTimeOrder(string $format, string $first, string $second, string $operator)
Given two date/time strings, check that one is after the other.
protected DateTime|null
getDateTimeWithOptionalFormat(string $format, string $value)
Get a DateTime instance from a string.
protected DateTime|null
getDateTime(string $value)
Get a DateTime instance from a string with no format.
bool
validateAlpha(string $attribute, mixed $value, $parameters)
Validate that an attribute contains only alphabetic characters.
If the 'ascii' option is passed, validate that an attribute contains only ascii alphabetic characters.
bool
validateAlphaDash(string $attribute, mixed $value, $parameters)
Validate that an attribute contains only alpha-numeric characters, dashes, and underscores.
If the 'ascii' option is passed, validate that an attribute contains only ascii alpha-numeric characters, dashes, and underscores.
bool
validateAlphaNum(string $attribute, mixed $value, $parameters)
Validate that an attribute contains only alpha-numeric characters.
If the 'ascii' option is passed, validate that an attribute contains only ascii alpha-numeric characters.
bool
validateArray(string $attribute, mixed $value, array<int,int|string> $parameters = [])
Validate that an attribute is an array.
bool
validateList(string $attribute, mixed $value)
Validate that an attribute is a list.
bool
validateRequiredArrayKeys(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an array has all of the given keys.
bool
validateBetween(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate the size of an attribute is between a set of values.
bool
validateBoolean(string $attribute, mixed $value)
Validate that an attribute is a boolean.
bool
validateConfirmed(string $attribute, mixed $value, $parameters)
Validate that an attribute has a matching confirmation.
bool
validateContains(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate an attribute contains a list of values.
protected bool
validateCurrentPassword(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that the password of the currently authenticated user matches the given value.
bool
validateDate(string $attribute, mixed $value)
Validate that an attribute is a valid date.
bool
validateDateFormat(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute matches a date format.
bool
validateDateEquals(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute is equal to another date.
bool
validateDecimal(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute has a given number of decimal places.
bool
validateDifferent(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute is different from another attribute.
bool
validateDigits(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute has a given number of digits.
bool
validateDigitsBetween(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute is between a given number of digits.
bool
validateDimensions(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate the dimensions of an image matches the given values.
protected bool
failsBasicDimensionChecks(array<string,string> $parameters, int $width, int $height)
Test if the given width and height fail any conditions.
protected bool
failsRatioCheck(array<string,string> $parameters, int $width, int $height)
Determine if the given parameters fail a dimension ratio check.
bool
validateDistinct(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate an attribute is unique among other values.
protected array
getDistinctValues(string $attribute)
Get the values to distinct between.
protected array
extractDistinctValues(string $attribute)
Extract the distinct values from the data.
bool
validateEmail(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute is a valid e-mail address.
bool
validateExists(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate the existence of an attribute value in a database table.
protected int
getExistCount(mixed $connection, string $table, string $column, mixed $value, array<int,int|string> $parameters)
Get the number of records that exist in storage.
bool
validateUnique(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate the uniqueness of an attribute value on a given database table.
If a database column is not specified, the attribute will be used.
protected array
getUniqueIds(string|null $idColumn, array<int,int|string> $parameters)
Get the excluded ID column and value for the unique rule.
protected int
prepareUniqueId(mixed $id)
Prepare the given ID for querying.
protected array
getUniqueExtra(array<int,int|string> $parameters)
Get the extra conditions for a unique rule.
array
parseTable(string $table)
Parse the connection / table for the unique / exists rules.
bool
getQueryColumn(array<int,int|string> $parameters, string $attribute)
Get the column name for an exists / unique query.
string
guessColumnForQuery(string $attribute)
Guess the database column from the given attribute name.
protected array
getExtraConditions(array $segments)
Get the extra conditions for a unique / exists rule.
bool
validateExtensions(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate the extension of a file upload attribute is in a set of defined extensions.
bool
validateFile(string $attribute, mixed $value)
Validate the given value is a valid file.
bool
validateFilled(string $attribute, mixed $value)
Validate the given attribute is filled if it is present.
bool
validateGt(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute is greater than another attribute.
bool
validateLt(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute is less than another attribute.
bool
validateGte(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute is greater than or equal another attribute.
bool
validateLte(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute is less than or equal another attribute.
bool
validateLowercase(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute is lowercase.
bool
validateUppercase(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute is uppercase.
bool
validateHexColor(string $attribute, mixed $value)
Validate that an attribute is a valid HEX color.
bool
validateImage(string $attribute, mixed $value)
Validate the MIME type of a file is an image MIME type.
bool
validateIn(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate an attribute is contained within a list of values.
bool
validateInArray(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that the values of an attribute are in another attribute.
bool
validateInteger(string $attribute, mixed $value)
Validate that an attribute is an integer.
bool
validateIp(string $attribute, mixed $value)
Validate that an attribute is a valid IP.
bool
validateIpv4(string $attribute, mixed $value)
Validate that an attribute is a valid IPv4.
bool
validateIpv6(string $attribute, mixed $value)
Validate that an attribute is a valid IPv6.
bool
validateMacAddress(string $attribute, mixed $value)
Validate that an attribute is a valid MAC address.
bool
validateJson(string $attribute, mixed $value)
Validate the attribute is a valid JSON string.
bool
validateMax(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate the size of an attribute is less than or equal to a maximum value.
bool
validateMaxDigits(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute has a maximum number of digits.
bool
validateMimes(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate the guessed extension of a file upload is in a set of file extensions.
bool
validateMimetypes(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate the MIME type of a file upload attribute is in a set of MIME types.
protected bool
shouldBlockPhpUpload(mixed $value, array<int,int|string> $parameters)
Check if PHP uploads are explicitly allowed.
bool
validateMin(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate the size of an attribute is greater than or equal to a minimum value.
bool
validateMinDigits(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute has a minimum number of digits.
bool
validateMissing(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute is missing.
bool
validateMissingIf(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute is missing when another attribute has a given value.
bool
validateMissingUnless(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute is missing unless another attribute has a given value.
bool
validateMissingWith(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute is missing when any given attribute is present.
bool
validateMissingWithAll(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute is missing when all given attributes are present.
bool
validateMultipleOf(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate the value of an attribute is a multiple of a given value.
bool
validateNullable()
"Indicate" validation should pass if value is null.
Always returns true, just lets us put "nullable" in rules.
bool
validateNotIn(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate an attribute is not contained within a list of values.
bool
validateNumeric(string $attribute, mixed $value)
Validate that an attribute is numeric.
bool
validatePresent(string $attribute, mixed $value)
Validate that an attribute exists even if not filled.
bool
validatePresentIf(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute is present when another attribute has a given value.
bool
validatePresentUnless(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute is present unless another attribute has a given value.
bool
validatePresentWith(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute is present when any given attribute is present.
bool
validatePresentWithAll(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute is present when all given attributes are present.
bool
validateRegex(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute passes a regular expression check.
bool
validateNotRegex(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that an attribute does not pass a regular expression check.
bool
validateRequired(string $attribute, mixed $value)
Validate that a required attribute exists.
bool
validateRequiredIf(string $attribute, mixed $value, mixed $parameters)
Validate that an attribute exists when another attribute has a given value.
bool
validateRequiredIfAccepted(string $attribute, mixed $value, mixed $parameters)
Validate that an attribute exists when another attribute was "accepted".
bool
validateRequiredIfDeclined(string $attribute, mixed $value, mixed $parameters)
Validate that an attribute exists when another attribute was "declined".
bool
validateProhibited(string $attribute, mixed $value)
Validate that an attribute does not exist or is an empty string.
bool
validateProhibitedIf(string $attribute, mixed $value, mixed $parameters)
Validate that an attribute does not exist when another attribute has a given value.
bool
validateProhibitedUnless(string $attribute, mixed $value, mixed $parameters)
Validate that an attribute does not exist unless another attribute has a given value.
bool
validateProhibits(string $attribute, mixed $value, mixed $parameters)
Validate that other attributes do not exist when this attribute exists.
bool
validateExclude()
Indicate that an attribute is excluded.
bool
validateExcludeIf(string $attribute, mixed $value, mixed $parameters)
Indicate that an attribute should be excluded when another attribute has a given value.
bool
validateExcludeUnless(string $attribute, mixed $value, mixed $parameters)
Indicate that an attribute should be excluded when another attribute does not have a given value.
bool
validateRequiredUnless(string $attribute, mixed $value, mixed $parameters)
Validate that an attribute exists when another attribute does not have a given value.
bool
validateExcludeWith(string $attribute, mixed $value, mixed $parameters)
Indicate that an attribute should be excluded when another attribute presents.
bool
validateExcludeWithout(string $attribute, mixed $value, mixed $parameters)
Indicate that an attribute should be excluded when another attribute is missing.
array
parseDependentRuleParameters(array<int,int|string> $parameters)
Prepare the values and the other value for validation.
protected bool
shouldConvertToBoolean(string $parameter)
Check if parameter should be converted to boolean.
protected array
convertValuesToBoolean(array $values)
Convert the given values to boolean if they are string "true" / "false".
protected array
convertValuesToNull(array $values)
Convert the given values to null if they are string "null".
bool
validateRequiredWith(string $attribute, mixed $value, mixed $parameters)
Validate that an attribute exists when any other attribute exists.
bool
validateRequiredWithAll(string $attribute, mixed $value, mixed $parameters)
Validate that an attribute exists when all other attributes exist.
bool
validateRequiredWithout(string $attribute, mixed $value, mixed $parameters)
Validate that an attribute exists when another attribute does not.
bool
validateRequiredWithoutAll(string $attribute, mixed $value, mixed $parameters)
Validate that an attribute exists when all other attributes do not.
protected bool
anyFailingRequired(array $attributes)
Determine if any of the given attributes fail the required test.
protected bool
allFailingRequired(array $attributes)
Determine if all of the given attributes fail the required test.
bool
validateSame(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate that two attributes match.
bool
validateSize(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate the size of an attribute.
bool
validateSometimes()
"Validate" optional attributes.
Always returns true, just lets us put sometimes in rules.
bool
validateStartsWith(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate the attribute starts with a given substring.
bool
validateDoesntStartWith(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate the attribute does not start with a given substring.
bool
validateEndsWith(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate the attribute ends with a given substring.
bool
validateDoesntEndWith(string $attribute, mixed $value, array<int,int|string> $parameters)
Validate the attribute does not end with a given substring.
bool
validateString(string $attribute, mixed $value)
Validate that an attribute is a string.
bool
validateTimezone(string $attribute, mixed $value, array<string,null|string> $parameters = [])
Validate that an attribute is a valid timezone.
bool
validateUrl(string $attribute, mixed $value, array<int,string> $parameters = [])
Validate that an attribute is a valid URL.
bool
validateUlid(string $attribute, mixed $value)
Validate that an attribute is a valid ULID.
bool
validateUuid(string $attribute, mixed $value, $parameters)
Validate that an attribute is a valid UUID.
protected int|float|string
getSize(string $attribute, mixed $value)
Get the size of an attribute.
bool
isValidFileInstance(mixed $value)
Check that the given value is a valid file instance.
protected bool
compare(mixed $first, mixed $second, string $operator)
Determine if a comparison passes between the given values.
array
parseNamedParameters(array<int,int|string> $parameters)
Parse named parameters to $key => $value items.
void
requireParameterCount(int $count, array<int,int|string> $parameters, string $rule)
Require a certain number of parameters to be present.
protected bool
isSameType(mixed $first, mixed $second)
Check if the parameters are of the same type.
protected void
shouldBeNumeric(string $attribute, string $rule)
Adds the existing rule to the numericRules array if the attribute's value is numeric.
protected mixed
trim(mixed $value)
Trim the value if it is a string.
protected mixed
ensureExponentWithinAllowedRange(string $attribute, mixed $value)
Ensure the exponent is within the allowed range.
void
__construct(Translator $translator, array $data, array $rules, array $messages = [], array $attributes = [])
Create a new Validator instance.
array
parseData(array $data)
Parse the data array, converting dots and asterisks.
protected array
replacePlaceholders(array $data)
Replace the placeholders used in data keys.
protected string
replacePlaceholderInString(string $value)
Replace the placeholders in the given string.
protected string
replaceDotPlaceholderInParameters(array $parameters)
Replace each field parameter dot placeholder with dot.
$this
after(callable|string $callback)
Add an after validation callback.
bool
passes()
Determine if the data passes the validation rules.
bool
fails()
Determine if the data fails the validation rules.
protected bool
shouldBeExcluded(string $attribute)
Determine if the attribute should be excluded.
protected void
removeAttribute(string $attribute)
Remove the given attribute.
array
validate()
Run the validator's rules against its data.
array
validateWithBag(string $errorBag)
Run the validator's rules against its data.
ValidatedInput|array
safe(array|null $keys = null)
Get a validated input container for the validated input.
array
validated()
Get the attributes and values that were validated.
protected void
validateAttribute(string $attribute, string $rule)
Validate a given attribute against a rule.
protected bool
dependsOnOtherFields(string $rule)
Determine if the given rule depends on other fields.
protected array
getExplicitKeys(string $attribute)
Get the explicit keys from an attribute flattened with dot notation.
E.g. 'foo.1.bar.spark.baz' -> [1, 'spark'] for 'foo..bar..baz'
protected string
getPrimaryAttribute(string $attribute)
Get the primary attribute name.
For example, if "name.0" is given, "name.*" will be returned.
protected array
replaceDotInParameters(array $parameters)
Replace each field parameter which has an escaped dot with the dot placeholder.
protected array
replaceAsterisksInParameters(array $parameters, array $keys)
Replace each field parameter which has asterisks with the given keys.
protected bool
isValidatable(object|string $rule, string $attribute, mixed $value)
Determine if the attribute is validatable.
protected bool
presentOrRuleIsImplicit(object|string $rule, string $attribute, mixed $value)
Determine if the field is present, or the rule implies required.
protected bool
isImplicit(object|string $rule)
Determine if a given rule implies the attribute is required.
protected bool
passesOptionalCheck(string $attribute)
Determine if the attribute passes any optional check.
protected bool
isNotNullIfMarkedAsNullable(string $rule, string $attribute)
Determine if the attribute fails the nullable check.
protected bool
hasNotFailedPreviousRuleIfPresenceRule(string $rule, string $attribute)
Determine if it's a necessary presence validation.
This is to avoid possible database type comparison errors.
protected void
validateUsingCustomRule(string $attribute, mixed $value, Rule $rule)
Validate an attribute using a custom rule object.
protected bool
shouldStopValidating(string $attribute)
Check if we should stop further validations on a given attribute.
void
addFailure(string $attribute, string $rule, array $parameters = [])
Add a failed rule and error message to the collection.
protected void
excludeAttribute(string $attribute)
Add the given attribute to the list of excluded attributes.
array
valid()
Returns the data which was valid.
array
invalid()
Returns the data which was invalid.
protected array
attributesThatHaveMessages()
Generate an array of all attributes that have messages.
array
failed()
Get the failed validation rules.
MessageBag
messages()
Get the message container for the validator.
MessageBag
errors()
An alternative more semantic shortcut to the message container.
MessageBag
getMessageBag()
Get the messages for the instance.
bool
hasRule(string $attribute, string|array $rules)
Determine if the given attribute has a rule in the given set.
protected array|null
getRule(string $attribute, string|array $rules)
Get a rule and its parameters for a given attribute.
array
attributes()
Get the data under validation.
array
getData()
Get the data under validation.
$this
setData(array $data)
Set the data under validation.
mixed
getValue(string $attribute)
Get the value of a given attribute.
void
setValue(string $attribute, mixed $value)
Set the value of a given attribute.
array
getRules()
Get the validation rules.
array
getRulesWithoutPlaceholders()
Get the validation rules with key placeholders removed.
$this
setRules(array $rules)
Set the validation rules.
void
addRules(array $rules)
Parse the given rules and merge them into current rules.
$this
sometimes(string|array $attribute, string|array $rules, callable $callback)
Add conditions to a given field based on a Closure.
$this
stopOnFirstFailure(bool $stopOnFirstFailure = true)
Instruct the validator to stop validating after the first rule failure.
void
addExtensions(array $extensions)
Register an array of custom validator extensions.
void
addImplicitExtensions(array $extensions)
Register an array of custom implicit validator extensions.
void
addDependentExtensions(array $extensions)
Register an array of custom dependent validator extensions.
void
addExtension(string $rule, Closure|string $extension)
Register a custom validator extension.
void
addImplicitExtension(string $rule, Closure|string $extension)
Register a custom implicit validator extension.
void
addDependentExtension(string $rule, Closure|string $extension)
Register a custom dependent validator extension.
void
addReplacers(array $replacers)
Register an array of custom validator message replacers.
void
addReplacer(string $rule, Closure|string $replacer)
Register a custom validator message replacer.
$this
setCustomMessages(array $messages)
Set the custom messages for the validator.
$this
setAttributeNames(array $attributes)
Set the custom attributes on the validator.
$this
addCustomAttributes(array $attributes)
Add custom attributes to the validator.
$this
setImplicitAttributesFormatter(callable|null $formatter = null)
Set the callback that used to format an implicit attribute.
$this
setValueNames(array $values)
Set the custom values on the validator.
$this
addCustomValues(array $customValues)
Add the custom values for the validator.
void
setFallbackMessages(array $messages)
Set the fallback messages for the validator.
PresenceVerifierInterface
getPresenceVerifier(string|null $connection = null)
Get the Presence Verifier implementation.
void
setPresenceVerifier(PresenceVerifierInterface $presenceVerifier)
Set the Presence Verifier implementation.
ValidationException>
getException()
Get the exception to throw upon failed validation.
$this
setException(ValidationException> $exception)
Set the exception to throw upon failed validation.
$this
ensureExponentWithinAllowedRangeUsing($callback)
Ensure exponents are within range using the given callback.
Translator
getTranslator()
Get the Translator implementation.
void
setTranslator(Translator $translator)
Set the Translator implementation.
void
setContainer(Container $container)
Set the IoC container instance.
protected bool|null
callExtension(string $rule, array $parameters)
Call a custom validator extension.
protected bool
callClassBasedExtension(string $callback, array $parameters)
Call a class based validator extension.
mixed
__call(string $method, array $parameters)
Handle dynamic calls to class methods.