class Validator implements Validator (View source)

Properties

protected TranslatorInterface $translator The Translator implementation.
protected PresenceVerifierInterface $presenceVerifier The Presence Verifier implementation.
protected Container $container The container instance.
protected array $failedRules The failed validation rules.
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 array $implicitAttributes The array of wildcard attributes with their asterisks expanded.
protected array $after All of the registered "after" callbacks.
protected array $customMessages The array of custom error messages.
protected array $fallbackMessages The array of fallback error messages.
protected array $customAttributes The array of custom attribute names.
protected array $customValues The array of custom displayable values.
protected array $extensions All of the custom validator extensions.
protected array $replacers All of the custom replacer extensions.
protected array $sizeRules The size related validation rules.
protected array $fileRules The validation rules that may be applied to files.
protected array $numericRules The numeric related validation rules.
protected array $implicitRules The validation rules that imply the field is required.
protected array $dependentRules The validation rules which depend on other fields as parameters.

Methods

void
__construct(TranslatorInterface $translator, array $data, array $rules, array $messages = [], array $customAttributes = [])

Create a new Validator instance.

array
parseData(array $data)

Parse the data array.

array
explodeRules(array $rules)

Explode the rules into an array of rules.

$this
after(callable|string $callback)

After an after validation callback.

void
sometimes(string $attribute, string|array $rules, callable $callback)

Add conditions to a given field based on a Closure.

void
each(string $attribute, string|array $rules)

Define a set of rules that apply to each element in an array attribute.

array
initializeAttributeOnData(string $attribute)

Gather a copy of the attribute data filled with any missing attributes.

array
extractValuesForWildcards(array $data, string $attribute)

Get all of the exact attribute values for a given wildcard attribute.

$this
mergeRules(string $attribute, string|array $rules = [])

Merge additional rules into a given attribute(s).

$this
mergeRulesForAttribute(string $attribute, string|array $rules)

Merge additional rules into a given attribute.

bool
passes()

Determine if the data passes the validation rules.

bool
fails()

Determine if the data fails the validation rules.

void
validate()

Run the validator's rules against its data.

void
validateAttribute(string $attribute, string $rule)

Validate a given attribute against a rule.

array
valid()

Returns the data which was valid.

array
invalid()

Returns the data which was invalid.

array
attributesThatHaveMessages()

Generate an array of all attributes that have messages.

mixed
getValue(string $attribute)

Get the value of a given attribute.

bool
isValidatable(string $rule, string $attribute, mixed $value)

Determine if the attribute is validatable.

bool
presentOrRuleIsImplicit(string $rule, string $attribute, mixed $value)

Determine if the field is present, or the rule implies required.

bool
passesOptionalCheck(string $attribute)

Determine if the attribute passes any optional check.

bool
isNotNullIfMarkedAsNullable(string $attribute, mixed $value)

Determine if the attribute fails the nullable check.

bool
isImplicit(string $rule)

Determine if a given rule implies the attribute is required.

bool
hasNotFailedPreviousRuleIfPresenceRule(string $rule, string $attribute)

Determine if it's a necessary presence validation.

void
addFailure(string $attribute, string $rule, array $parameters)

Add a failed rule and error message to the collection.

void
addError(string $attribute, string $rule, array $parameters)

Add an error message to the validator's collection of messages.

bool
validateSometimes()

"Validate" optional attributes.

bool
validateNullable()

"Indicate" validation should pass if value is null.

bool
validateBail()

"Break" on first validation fail.

bool
shouldStopValidating(string $attribute)

Check if we should stop further validations on a given attribute.

bool
validateRequired(string $attribute, mixed $value)

Validate that a required attribute exists.

bool
validatePresent(string $attribute, mixed $value)

Validate that an attribute exists even if not filled.

bool
validateFilled(string $attribute, mixed $value)

Validate the given attribute is filled if it is present.

bool
anyFailingRequired(array $attributes)

Determine if any of the given attributes fail the required test.

bool
allFailingRequired(array $attributes)

Determine if all of the given attributes fail the required test.

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 exists.

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.

bool
validateRequiredIf(string $attribute, mixed $value, mixed $parameters)

Validate that an attribute exists when another attribute has 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.

int
getPresentCount(array $attributes)

Get the number of attributes in a list that are present.

bool
validateInArray(string $attribute, mixed $value, array $parameters)

Validate that the values of an attribute is in another attribute.

bool
validateConfirmed(string $attribute, mixed $value)

Validate that an attribute has a matching confirmation.

bool
validateSame(string $attribute, mixed $value, array $parameters)

Validate that two attributes match.

bool
validateDifferent(string $attribute, mixed $value, array $parameters)

Validate that an attribute is different from another attribute.

bool
validateAccepted(string $attribute, mixed $value)

Validate that an attribute was "accepted".

bool
validateArray(string $attribute, mixed $value)

Validate that an attribute is an array.

bool
validateBoolean(string $attribute, mixed $value)

Validate that an attribute is a boolean.

bool
validateInteger(string $attribute, mixed $value)

Validate that an attribute is an integer.

bool
validateNumeric(string $attribute, mixed $value)

Validate that an attribute is numeric.

bool
validateString(string $attribute, mixed $value)

Validate that an attribute is a string.

bool
validateJson(string $attribute, mixed $value)

Validate the attribute is a valid JSON string.

bool
validateDigits(string $attribute, mixed $value, array $parameters)

Validate that an attribute has a given number of digits.

bool
validateDigitsBetween(string $attribute, mixed $value, array $parameters)

Validate that an attribute is between a given number of digits.

bool
validateSize(string $attribute, mixed $value, array $parameters)

Validate the size of an attribute.

bool
validateBetween(string $attribute, mixed $value, array $parameters)

Validate the size of an attribute is between a set of values.

bool
validateMin(string $attribute, mixed $value, array $parameters)

Validate the size of an attribute is greater than a minimum value.

bool
validateMax(string $attribute, mixed $value, array $parameters)

Validate the size of an attribute is less than a maximum value.

mixed
getSize(string $attribute, mixed $value)

Get the size of an attribute.

bool
validateIn(string $attribute, mixed $value, array $parameters)

Validate an attribute is contained within a list of values.

bool
validateNotIn(string $attribute, mixed $value, array $parameters)

Validate an attribute is not contained within a list of values.

bool
validateDistinct(string $attribute, mixed $value, array $parameters)

Validate an attribute is unique among other values.

bool
validateUnique(string $attribute, mixed $value, array $parameters)

Validate the uniqueness of an attribute value on a given database table.

array
parseTable(string $table)

Parse the connection / table for the unique / exists rules.

array
getUniqueIds(array $parameters)

Get the excluded ID column and value for the unique rule.

array
getUniqueExtra(array $parameters)

Get the extra conditions for a unique rule.

bool
validateExists(string $attribute, mixed $value, array $parameters)

Validate the existence of an attribute value in a database table.

int
getExistCount(mixed $connection, string $table, string $column, mixed $value, array $parameters)

Get the number of records that exist in storage.

array
getExtraExistConditions(array $parameters)

Get the extra exist conditions.

array
getExtraConditions(array $segments)

Get the extra conditions for a unique / exists rule.

string
guessColumnForQuery(string $attribute)

Guess the database column from the given attribute name.

bool
validateIp(string $attribute, mixed $value)

Validate that an attribute is a valid IP.

bool
validateEmail(string $attribute, mixed $value)

Validate that an attribute is a valid e-mail address.

bool
validateUrl(string $attribute, mixed $value)

Validate that an attribute is a valid URL.

bool
validateActiveUrl(string $attribute, mixed $value)

Validate that an attribute is an active URL.

bool
validateFile(string $attribute, mixed $value)

Validate the given value is a valid file.

bool
validateImage(string $attribute, mixed $value)

Validate the MIME type of a file is an image MIME type.

bool
validateDimensions(string $attribute, mixed $value, array $parameters)

Validate the dimensions of an image matches the given values.

bool
validateMimes(string $attribute, mixed $value, array $parameters)

Validate the guessed extension of a file upload is in a set of file extensions.

bool
validateMimetypes(string $attribute, mixed $value, array $parameters)

Validate the MIME type of a file upload attribute is in a set of MIME types.

shouldBlockPhpUpload($value, $parameters)

No description

bool
isAValidFileInstance(mixed $value)

Check that the given value is a valid file instance.

bool
validateAlpha(string $attribute, mixed $value)

Validate that an attribute contains only alphabetic characters.

bool
validateAlphaNum(string $attribute, mixed $value)

Validate that an attribute contains only alpha-numeric characters.

bool
validateAlphaDash(string $attribute, mixed $value)

Validate that an attribute contains only alpha-numeric characters, dashes, and underscores.

bool
validateRegex(string $attribute, mixed $value, array $parameters)

Validate that an attribute passes a regular expression check.

bool
validateDate(string $attribute, mixed $value)

Validate that an attribute is a valid date.

bool
validateDateFormat(string $attribute, mixed $value, array $parameters)

Validate that an attribute matches a date format.

bool
validateBefore(string $attribute, mixed $value, array $parameters)

Validate the date is before a given date.

bool
validateBeforeOrEqual(string $attribute, mixed $value, array $parameters)

Validate the date is before or equal a given date.

bool
validateAfter(string $attribute, mixed $value, array $parameters)

Validate the date is after a given date.

bool
validateAfterOrEqual(string $attribute, mixed $value, array $parameters)

Validate the date is equal or after a given date.

bool
compareDates(string $attribute, mixed $value, array $parameters, string $operator)

Compare a given date against another using an operator.

bool
checkDateTimeOrder(string $format, string $first, string $second, string $operator)

Given two date/time strings, check that one is after the other.

DateTime|null
getDateTimeWithOptionalFormat(string $format, string $value)

Get a DateTime instance from a string.

bool
validateTimezone(string $attribute, mixed $value)

Validate that an attribute is a valid timezone.

string|null
getDateFormat(string $attribute)

Get the date format for an attribute if it has one.

int
getDateTimestamp(mixed $value)

Get the date timestamp.

string
getMessage(string $attribute, string $rule)

Get the validation message for an attribute and rule.

string|null
getInlineMessage(string $attribute, string $lowerRule, array $source = null)

Get the inline message for a rule if it exists.

string
getCustomMessageFromTranslator(string $customKey)

Get the custom error message from translator.

string
getSizeMessage(string $attribute, string $rule)

Get the proper error message for an attribute and size rule.

string
getAttributeType(string $attribute)

Get the data type of the given attribute.

string
doReplacements(string $message, string $attribute, string $rule, array $parameters)

Replace all error message place-holders with actual values.

array
getAttributeList(array $values)

Transform an array of attributes to their displayable form.

string
getAttribute(string $attribute)

Get the displayable name of the attribute.

string
getPrimaryAttribute(string $attribute)

Get the primary attribute name.

string
getDisplayableValue(string $attribute, mixed $value)

Get the displayable name of the value.

string
replaceBetween(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the between rule.

string
replaceDateFormat(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the date_format rule.

string
replaceDifferent(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the different rule.

string
replaceDigits(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the digits rule.

string
replaceDigitsBetween(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the digits (between) rule.

string
replaceMin(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the min rule.

string
replaceMax(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the max rule.

string
replaceIn(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the in rule.

string
replaceNotIn(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the not_in rule.

string
replaceInArray(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the in_array rule.

string
replaceMimetypes(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the mimetypes rule.

string
replaceMimes(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the mimes rule.

string
replaceRequiredWith(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the required_with rule.

string
replaceRequiredWithAll(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the required_with_all rule.

string
replaceRequiredWithout(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the required_without rule.

string
replaceRequiredWithoutAll(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the required_without_all rule.

string
replaceSize(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the size rule.

string
replaceRequiredIf(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the required_if rule.

string
replaceRequiredUnless(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the required_unless rule.

string
replaceSame(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the same rule.

string
replaceBefore(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the before rule.

string
replaceAfter(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the after rule.

array
attributes()

Get all attributes.

bool
hasAttribute(string $attribute)

Checks if an attribute exists.

bool
hasRule(string $attribute, string|array $rules)

Determine if the given attribute has a rule in the given set.

array|null
getRule(string $attribute, string|array $rules)

Get a rule and its parameters for a given attribute.

array
parseRule(array|string $rules)

Extract the rule name and parameters from a rule.

array
parseArrayRule(array $rules)

Parse an array based rule.

array
parseStringRule(string $rules)

Parse a string based rule.

array
parseParameters(string $rule, string $parameter)

Parse a parameter list.

array
parseNamedParameters(array $parameters)

Parse named parameters to $key => $value items.

string
normalizeRule(string $rule)

Normalizes a rule so that we can accept short types.

bool
dependsOnOtherFields(string $rule)

Determine if the given rule depends on other fields.

array
getExplicitKeys(string $attribute)

Get the explicit keys from an attribute flattened with dot notation.

string
getLeadingExplicitAttributePath(string $attribute)

Get the explicit part of the attribute name.

array
extractDataFromPath(string $attribute)

Extract data based on the given dot-notated path.

array
replaceAsterisksInParameters(array $parameters, array $keys)

Replace each field parameter which has asterisks with the given keys.

string
replaceAsterisksWithKeys(string $field, array $keys)

Replace asterisks with explicit keys.

array
getExtensions()

Get the array of custom validator extensions.

void
addExtensions(array $extensions)

Register an array of custom validator extensions.

void
addImplicitExtensions(array $extensions)

Register an array of custom implicit 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.

array
getReplacers()

Get the array of custom validator message replacers.

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.

array
getData()

Get the data under validation.

$this
setData(array $data)

Set the data under validation.

array
getRules()

Get the validation rules.

$this
setRules(array $rules)

Set the validation rules.

$this
setAttributeNames(array $attributes)

Set the custom attributes on the validator.

$this
setValueNames(array $values)

Set the custom values on the validator.

getPresenceVerifier()

Get the Presence Verifier implementation.

void
setPresenceVerifier(PresenceVerifierInterface $presenceVerifier)

Set the Presence Verifier implementation.

TranslatorInterface
getTranslator()

Get the Translator implementation.

void
setTranslator(TranslatorInterface $translator)

Set the Translator implementation.

array
getCustomMessages()

Get the custom messages for the validator.

void
setCustomMessages(array $messages)

Set the custom messages for the validator.

array
getCustomAttributes()

Get the custom attributes used by the validator.

$this
addCustomAttributes(array $customAttributes)

Add custom attributes to the validator.

array
getCustomValues()

Get the custom values for the validator.

$this
addCustomValues(array $customValues)

Add the custom values for the validator.

array
getFallbackMessages()

Get the fallback messages for the validator.

void
setFallbackMessages(array $messages)

Set the fallback messages for the validator.

array
failed()

Get the failed validation rules.

messages()

Get the message container for the validator.

errors()

An alternative more semantic shortcut to the message container.

getMessageBag()

Get the messages for the instance.

void
setContainer(Container $container)

Set the IoC container instance.

bool|null
callExtension(string $rule, array $parameters)

Call a custom validator extension.

bool
callClassBasedExtension(string $callback, array $parameters)

Call a class based validator extension.

string|null
callReplacer(string $message, string $attribute, string $rule, array $parameters)

Call a custom validator message replacer.

string
callClassBasedReplacer(string $callback, string $message, string $attribute, string $rule, array $parameters)

Call a class based validator message replacer.

void
requireParameterCount(int $count, array $parameters, string $rule)

Require a certain number of parameters to be present.

bool
compare(mixed $first, mixed $second, string $operator)

Determine if a comparison passes between the given values.

mixed
__call(string $method, array $parameters)

Handle dynamic calls to class methods.

Details

void __construct(TranslatorInterface $translator, array $data, array $rules, array $messages = [], array $customAttributes = [])

Create a new Validator instance.

Parameters

TranslatorInterface $translator
array $data
array $rules
array $messages
array $customAttributes

Return Value

void

array parseData(array $data)

Parse the data array.

Parameters

array $data

Return Value

array

protected array explodeRules(array $rules)

Explode the rules into an array of rules.

Parameters

array $rules

Return Value

array

$this after(callable|string $callback)

After an after validation callback.

Parameters

callable|string $callback

Return Value

$this

void sometimes(string $attribute, string|array $rules, callable $callback)

Add conditions to a given field based on a Closure.

Parameters

string $attribute
string|array $rules
callable $callback

Return Value

void

void each(string $attribute, string|array $rules)

Define a set of rules that apply to each element in an array attribute.

Parameters

string $attribute
string|array $rules

Return Value

void

Exceptions

InvalidArgumentException

protected array initializeAttributeOnData(string $attribute)

Gather a copy of the attribute data filled with any missing attributes.

Parameters

string $attribute

Return Value

array

array extractValuesForWildcards(array $data, string $attribute)

Get all of the exact attribute values for a given wildcard attribute.

Parameters

array $data
string $attribute

Return Value

array

$this mergeRules(string $attribute, string|array $rules = [])

Merge additional rules into a given attribute(s).

Parameters

string $attribute
string|array $rules

Return Value

$this

protected $this mergeRulesForAttribute(string $attribute, string|array $rules)

Merge additional rules into a given attribute.

Parameters

string $attribute
string|array $rules

Return Value

$this

bool passes()

Determine if the data passes the validation rules.

Return Value

bool

bool fails()

Determine if the data fails the validation rules.

Return Value

bool

void validate()

Run the validator's rules against its data.

Return Value

void

Exceptions

ValidationException

protected void validateAttribute(string $attribute, string $rule)

Validate a given attribute against a rule.

Parameters

string $attribute
string $rule

Return Value

void

array valid()

Returns the data which was valid.

Return Value

array

array invalid()

Returns the data which was invalid.

Return Value

array

protected array attributesThatHaveMessages()

Generate an array of all attributes that have messages.

Return Value

array

protected mixed getValue(string $attribute)

Get the value of a given attribute.

Parameters

string $attribute

Return Value

mixed

protected bool isValidatable(string $rule, string $attribute, mixed $value)

Determine if the attribute is validatable.

Parameters

string $rule
string $attribute
mixed $value

Return Value

bool

protected bool presentOrRuleIsImplicit(string $rule, string $attribute, mixed $value)

Determine if the field is present, or the rule implies required.

Parameters

string $rule
string $attribute
mixed $value

Return Value

bool

protected bool passesOptionalCheck(string $attribute)

Determine if the attribute passes any optional check.

Parameters

string $attribute

Return Value

bool

protected bool isNotNullIfMarkedAsNullable(string $attribute, mixed $value)

Determine if the attribute fails the nullable check.

Parameters

string $attribute
mixed $value

Return Value

bool

protected bool isImplicit(string $rule)

Determine if a given rule implies the attribute is required.

Parameters

string $rule

Return Value

bool

protected bool hasNotFailedPreviousRuleIfPresenceRule(string $rule, string $attribute)

Determine if it's a necessary presence validation.

This is to avoid possible database type comparison errors.

Parameters

string $rule
string $attribute

Return Value

bool

protected void addFailure(string $attribute, string $rule, array $parameters)

Add a failed rule and error message to the collection.

Parameters

string $attribute
string $rule
array $parameters

Return Value

void

protected void addError(string $attribute, string $rule, array $parameters)

Add an error message to the validator's collection of messages.

Parameters

string $attribute
string $rule
array $parameters

Return Value

void

protected bool validateSometimes()

"Validate" optional attributes.

Always returns true, just lets us put sometimes in rules.

Return Value

bool

protected bool validateNullable()

"Indicate" validation should pass if value is null.

Always returns true, just lets us put "nullable" in rules.

Return Value

bool

protected bool validateBail()

"Break" on first validation fail.

Always returns true, just lets us put "bail" in rules.

Return Value

bool

protected bool shouldStopValidating(string $attribute)

Check if we should stop further validations on a given attribute.

Parameters

string $attribute

Return Value

bool

protected bool validateRequired(string $attribute, mixed $value)

Validate that a required attribute exists.

Parameters

string $attribute
mixed $value

Return Value

bool

protected bool validatePresent(string $attribute, mixed $value)

Validate that an attribute exists even if not filled.

Parameters

string $attribute
mixed $value

Return Value

bool

protected bool validateFilled(string $attribute, mixed $value)

Validate the given attribute is filled if it is present.

Parameters

string $attribute
mixed $value

Return Value

bool

protected bool anyFailingRequired(array $attributes)

Determine if any of the given attributes fail the required test.

Parameters

array $attributes

Return Value

bool

protected bool allFailingRequired(array $attributes)

Determine if all of the given attributes fail the required test.

Parameters

array $attributes

Return Value

bool

protected bool validateRequiredWith(string $attribute, mixed $value, mixed $parameters)

Validate that an attribute exists when any other attribute exists.

Parameters

string $attribute
mixed $value
mixed $parameters

Return Value

bool

protected bool validateRequiredWithAll(string $attribute, mixed $value, mixed $parameters)

Validate that an attribute exists when all other attributes exists.

Parameters

string $attribute
mixed $value
mixed $parameters

Return Value

bool

protected bool validateRequiredWithout(string $attribute, mixed $value, mixed $parameters)

Validate that an attribute exists when another attribute does not.

Parameters

string $attribute
mixed $value
mixed $parameters

Return Value

bool

protected bool validateRequiredWithoutAll(string $attribute, mixed $value, mixed $parameters)

Validate that an attribute exists when all other attributes do not.

Parameters

string $attribute
mixed $value
mixed $parameters

Return Value

bool

protected bool validateRequiredIf(string $attribute, mixed $value, mixed $parameters)

Validate that an attribute exists when another attribute has a given value.

Parameters

string $attribute
mixed $value
mixed $parameters

Return Value

bool

protected bool validateRequiredUnless(string $attribute, mixed $value, mixed $parameters)

Validate that an attribute exists when another attribute does not have a given value.

Parameters

string $attribute
mixed $value
mixed $parameters

Return Value

bool

protected int getPresentCount(array $attributes)

Get the number of attributes in a list that are present.

Parameters

array $attributes

Return Value

int

protected bool validateInArray(string $attribute, mixed $value, array $parameters)

Validate that the values of an attribute is in another attribute.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

protected bool validateConfirmed(string $attribute, mixed $value)

Validate that an attribute has a matching confirmation.

Parameters

string $attribute
mixed $value

Return Value

bool

protected bool validateSame(string $attribute, mixed $value, array $parameters)

Validate that two attributes match.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

protected bool validateDifferent(string $attribute, mixed $value, array $parameters)

Validate that an attribute is different from another attribute.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

protected bool validateAccepted(string $attribute, mixed $value)

Validate that an attribute was "accepted".

This validation rule implies the attribute is "required".

Parameters

string $attribute
mixed $value

Return Value

bool

protected bool validateArray(string $attribute, mixed $value)

Validate that an attribute is an array.

Parameters

string $attribute
mixed $value

Return Value

bool

protected bool validateBoolean(string $attribute, mixed $value)

Validate that an attribute is a boolean.

Parameters

string $attribute
mixed $value

Return Value

bool

protected bool validateInteger(string $attribute, mixed $value)

Validate that an attribute is an integer.

Parameters

string $attribute
mixed $value

Return Value

bool

protected bool validateNumeric(string $attribute, mixed $value)

Validate that an attribute is numeric.

Parameters

string $attribute
mixed $value

Return Value

bool

protected bool validateString(string $attribute, mixed $value)

Validate that an attribute is a string.

Parameters

string $attribute
mixed $value

Return Value

bool

protected bool validateJson(string $attribute, mixed $value)

Validate the attribute is a valid JSON string.

Parameters

string $attribute
mixed $value

Return Value

bool

protected bool validateDigits(string $attribute, mixed $value, array $parameters)

Validate that an attribute has a given number of digits.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

protected bool validateDigitsBetween(string $attribute, mixed $value, array $parameters)

Validate that an attribute is between a given number of digits.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

protected bool validateSize(string $attribute, mixed $value, array $parameters)

Validate the size of an attribute.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

protected bool validateBetween(string $attribute, mixed $value, array $parameters)

Validate the size of an attribute is between a set of values.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

protected bool validateMin(string $attribute, mixed $value, array $parameters)

Validate the size of an attribute is greater than a minimum value.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

protected bool validateMax(string $attribute, mixed $value, array $parameters)

Validate the size of an attribute is less than a maximum value.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

protected mixed getSize(string $attribute, mixed $value)

Get the size of an attribute.

Parameters

string $attribute
mixed $value

Return Value

mixed

protected bool validateIn(string $attribute, mixed $value, array $parameters)

Validate an attribute is contained within a list of values.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

protected bool validateNotIn(string $attribute, mixed $value, array $parameters)

Validate an attribute is not contained within a list of values.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

protected bool validateDistinct(string $attribute, mixed $value, array $parameters)

Validate an attribute is unique among other values.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

protected bool validateUnique(string $attribute, mixed $value, array $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.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

protected array parseTable(string $table)

Parse the connection / table for the unique / exists rules.

Parameters

string $table

Return Value

array

protected array getUniqueIds(array $parameters)

Get the excluded ID column and value for the unique rule.

Parameters

array $parameters

Return Value

array

protected array getUniqueExtra(array $parameters)

Get the extra conditions for a unique rule.

Parameters

array $parameters

Return Value

array

protected bool validateExists(string $attribute, mixed $value, array $parameters)

Validate the existence of an attribute value in a database table.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

protected int getExistCount(mixed $connection, string $table, string $column, mixed $value, array $parameters)

Get the number of records that exist in storage.

Parameters

mixed $connection
string $table
string $column
mixed $value
array $parameters

Return Value

int

protected array getExtraExistConditions(array $parameters)

Get the extra exist conditions.

Parameters

array $parameters

Return Value

array

protected array getExtraConditions(array $segments)

Get the extra conditions for a unique / exists rule.

Parameters

array $segments

Return Value

array

string guessColumnForQuery(string $attribute)

Guess the database column from the given attribute name.

Parameters

string $attribute

Return Value

string

protected bool validateIp(string $attribute, mixed $value)

Validate that an attribute is a valid IP.

Parameters

string $attribute
mixed $value

Return Value

bool

protected bool validateEmail(string $attribute, mixed $value)

Validate that an attribute is a valid e-mail address.

Parameters

string $attribute
mixed $value

Return Value

bool

protected bool validateUrl(string $attribute, mixed $value)

Validate that an attribute is a valid URL.

Parameters

string $attribute
mixed $value

Return Value

bool

protected bool validateActiveUrl(string $attribute, mixed $value)

Validate that an attribute is an active URL.

Parameters

string $attribute
mixed $value

Return Value

bool

protected bool validateFile(string $attribute, mixed $value)

Validate the given value is a valid file.

Parameters

string $attribute
mixed $value

Return Value

bool

protected bool validateImage(string $attribute, mixed $value)

Validate the MIME type of a file is an image MIME type.

Parameters

string $attribute
mixed $value

Return Value

bool

protected bool validateDimensions(string $attribute, mixed $value, array $parameters)

Validate the dimensions of an image matches the given values.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

protected bool validateMimes(string $attribute, mixed $value, array $parameters)

Validate the guessed extension of a file upload is in a set of file extensions.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

protected bool validateMimetypes(string $attribute, mixed $value, array $parameters)

Validate the MIME type of a file upload attribute is in a set of MIME types.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

protected shouldBlockPhpUpload($value, $parameters)

Parameters

$value
$parameters

bool isAValidFileInstance(mixed $value)

Check that the given value is a valid file instance.

Parameters

mixed $value

Return Value

bool

protected bool validateAlpha(string $attribute, mixed $value)

Validate that an attribute contains only alphabetic characters.

Parameters

string $attribute
mixed $value

Return Value

bool

protected bool validateAlphaNum(string $attribute, mixed $value)

Validate that an attribute contains only alpha-numeric characters.

Parameters

string $attribute
mixed $value

Return Value

bool

protected bool validateAlphaDash(string $attribute, mixed $value)

Validate that an attribute contains only alpha-numeric characters, dashes, and underscores.

Parameters

string $attribute
mixed $value

Return Value

bool

protected bool validateRegex(string $attribute, mixed $value, array $parameters)

Validate that an attribute passes a regular expression check.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

protected bool validateDate(string $attribute, mixed $value)

Validate that an attribute is a valid date.

Parameters

string $attribute
mixed $value

Return Value

bool

protected bool validateDateFormat(string $attribute, mixed $value, array $parameters)

Validate that an attribute matches a date format.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

protected bool validateBefore(string $attribute, mixed $value, array $parameters)

Validate the date is before a given date.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

protected bool validateBeforeOrEqual(string $attribute, mixed $value, array $parameters)

Validate the date is before or equal a given date.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

protected bool validateAfter(string $attribute, mixed $value, array $parameters)

Validate the date is after a given date.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

protected bool validateAfterOrEqual(string $attribute, mixed $value, array $parameters)

Validate the date is equal or after a given date.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

protected bool compareDates(string $attribute, mixed $value, array $parameters, string $operator)

Compare a given date against another using an operator.

Parameters

string $attribute
mixed $value
array $parameters
string $operator

Return Value

bool

protected bool checkDateTimeOrder(string $format, string $first, string $second, string $operator)

Given two date/time strings, check that one is after the other.

Parameters

string $format
string $first
string $second
string $operator

Return Value

bool

protected DateTime|null getDateTimeWithOptionalFormat(string $format, string $value)

Get a DateTime instance from a string.

Parameters

string $format
string $value

Return Value

DateTime|null

protected bool validateTimezone(string $attribute, mixed $value)

Validate that an attribute is a valid timezone.

Parameters

string $attribute
mixed $value

Return Value

bool

protected string|null getDateFormat(string $attribute)

Get the date format for an attribute if it has one.

Parameters

string $attribute

Return Value

string|null

protected int getDateTimestamp(mixed $value)

Get the date timestamp.

Parameters

mixed $value

Return Value

int

protected string getMessage(string $attribute, string $rule)

Get the validation message for an attribute and rule.

Parameters

string $attribute
string $rule

Return Value

string

protected string|null getInlineMessage(string $attribute, string $lowerRule, array $source = null)

Get the inline message for a rule if it exists.

Parameters

string $attribute
string $lowerRule
array $source

Return Value

string|null

protected string getCustomMessageFromTranslator(string $customKey)

Get the custom error message from translator.

Parameters

string $customKey

Return Value

string

protected string getSizeMessage(string $attribute, string $rule)

Get the proper error message for an attribute and size rule.

Parameters

string $attribute
string $rule

Return Value

string

protected string getAttributeType(string $attribute)

Get the data type of the given attribute.

Parameters

string $attribute

Return Value

string

protected string doReplacements(string $message, string $attribute, string $rule, array $parameters)

Replace all error message place-holders with actual values.

Parameters

string $message
string $attribute
string $rule
array $parameters

Return Value

string

protected array getAttributeList(array $values)

Transform an array of attributes to their displayable form.

Parameters

array $values

Return Value

array

protected string getAttribute(string $attribute)

Get the displayable name of the attribute.

Parameters

string $attribute

Return Value

string

protected string getPrimaryAttribute(string $attribute)

Get the primary attribute name.

For example, if "name.0" is given, "name.*" will be returned.

Parameters

string $attribute

Return Value

string

string getDisplayableValue(string $attribute, mixed $value)

Get the displayable name of the value.

Parameters

string $attribute
mixed $value

Return Value

string

protected string replaceBetween(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the between rule.

Parameters

string $message
string $attribute
string $rule
array $parameters

Return Value

string

protected string replaceDateFormat(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the date_format rule.

Parameters

string $message
string $attribute
string $rule
array $parameters

Return Value

string

protected string replaceDifferent(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the different rule.

Parameters

string $message
string $attribute
string $rule
array $parameters

Return Value

string

protected string replaceDigits(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the digits rule.

Parameters

string $message
string $attribute
string $rule
array $parameters

Return Value

string

protected string replaceDigitsBetween(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the digits (between) rule.

Parameters

string $message
string $attribute
string $rule
array $parameters

Return Value

string

protected string replaceMin(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the min rule.

Parameters

string $message
string $attribute
string $rule
array $parameters

Return Value

string

protected string replaceMax(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the max rule.

Parameters

string $message
string $attribute
string $rule
array $parameters

Return Value

string

protected string replaceIn(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the in rule.

Parameters

string $message
string $attribute
string $rule
array $parameters

Return Value

string

protected string replaceNotIn(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the not_in rule.

Parameters

string $message
string $attribute
string $rule
array $parameters

Return Value

string

protected string replaceInArray(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the in_array rule.

Parameters

string $message
string $attribute
string $rule
array $parameters

Return Value

string

protected string replaceMimetypes(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the mimetypes rule.

Parameters

string $message
string $attribute
string $rule
array $parameters

Return Value

string

protected string replaceMimes(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the mimes rule.

Parameters

string $message
string $attribute
string $rule
array $parameters

Return Value

string

protected string replaceRequiredWith(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the required_with rule.

Parameters

string $message
string $attribute
string $rule
array $parameters

Return Value

string

protected string replaceRequiredWithAll(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the required_with_all rule.

Parameters

string $message
string $attribute
string $rule
array $parameters

Return Value

string

protected string replaceRequiredWithout(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the required_without rule.

Parameters

string $message
string $attribute
string $rule
array $parameters

Return Value

string

protected string replaceRequiredWithoutAll(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the required_without_all rule.

Parameters

string $message
string $attribute
string $rule
array $parameters

Return Value

string

protected string replaceSize(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the size rule.

Parameters

string $message
string $attribute
string $rule
array $parameters

Return Value

string

protected string replaceRequiredIf(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the required_if rule.

Parameters

string $message
string $attribute
string $rule
array $parameters

Return Value

string

protected string replaceRequiredUnless(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the required_unless rule.

Parameters

string $message
string $attribute
string $rule
array $parameters

Return Value

string

protected string replaceSame(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the same rule.

Parameters

string $message
string $attribute
string $rule
array $parameters

Return Value

string

protected string replaceBefore(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the before rule.

Parameters

string $message
string $attribute
string $rule
array $parameters

Return Value

string

protected string replaceAfter(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the after rule.

Parameters

string $message
string $attribute
string $rule
array $parameters

Return Value

string

array attributes()

Get all attributes.

Return Value

array

bool hasAttribute(string $attribute)

Checks if an attribute exists.

Parameters

string $attribute

Return Value

bool

bool hasRule(string $attribute, string|array $rules)

Determine if the given attribute has a rule in the given set.

Parameters

string $attribute
string|array $rules

Return Value

bool

protected array|null getRule(string $attribute, string|array $rules)

Get a rule and its parameters for a given attribute.

Parameters

string $attribute
string|array $rules

Return Value

array|null

protected array parseRule(array|string $rules)

Extract the rule name and parameters from a rule.

Parameters

array|string $rules

Return Value

array

protected array parseArrayRule(array $rules)

Parse an array based rule.

Parameters

array $rules

Return Value

array

protected array parseStringRule(string $rules)

Parse a string based rule.

Parameters

string $rules

Return Value

array

protected array parseParameters(string $rule, string $parameter)

Parse a parameter list.

Parameters

string $rule
string $parameter

Return Value

array

protected array parseNamedParameters(array $parameters)

Parse named parameters to $key => $value items.

Parameters

array $parameters

Return Value

array

protected string normalizeRule(string $rule)

Normalizes a rule so that we can accept short types.

Parameters

string $rule

Return Value

string

protected bool dependsOnOtherFields(string $rule)

Determine if the given rule depends on other fields.

Parameters

string $rule

Return Value

bool

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'

Parameters

string $attribute

Return Value

array

protected string getLeadingExplicitAttributePath(string $attribute)

Get the explicit part of the attribute name.

E.g. 'foo.bar.*.baz' -> 'foo.bar'

Allows us to not spin through all of the flattened data for some operations.

Parameters

string $attribute

Return Value

string

protected array extractDataFromPath(string $attribute)

Extract data based on the given dot-notated path.

Used to extract a sub-section of the data for faster iteration.

Parameters

string $attribute

Return Value

array

protected array replaceAsterisksInParameters(array $parameters, array $keys)

Replace each field parameter which has asterisks with the given keys.

Parameters

array $parameters
array $keys

Return Value

array

protected string replaceAsterisksWithKeys(string $field, array $keys)

Replace asterisks with explicit keys.

E.g. 'foo..bar..baz', [1, 'spark'] -> foo.1.bar.spark.baz

Parameters

string $field
array $keys

Return Value

string

array getExtensions()

Get the array of custom validator extensions.

Return Value

array

void addExtensions(array $extensions)

Register an array of custom validator extensions.

Parameters

array $extensions

Return Value

void

void addImplicitExtensions(array $extensions)

Register an array of custom implicit validator extensions.

Parameters

array $extensions

Return Value

void

void addExtension(string $rule, Closure|string $extension)

Register a custom validator extension.

Parameters

string $rule
Closure|string $extension

Return Value

void

void addImplicitExtension(string $rule, Closure|string $extension)

Register a custom implicit validator extension.

Parameters

string $rule
Closure|string $extension

Return Value

void

array getReplacers()

Get the array of custom validator message replacers.

Return Value

array

void addReplacers(array $replacers)

Register an array of custom validator message replacers.

Parameters

array $replacers

Return Value

void

void addReplacer(string $rule, Closure|string $replacer)

Register a custom validator message replacer.

Parameters

string $rule
Closure|string $replacer

Return Value

void

array getData()

Get the data under validation.

Return Value

array

$this setData(array $data)

Set the data under validation.

Parameters

array $data

Return Value

$this

array getRules()

Get the validation rules.

Return Value

array

$this setRules(array $rules)

Set the validation rules.

Parameters

array $rules

Return Value

$this

$this setAttributeNames(array $attributes)

Set the custom attributes on the validator.

Parameters

array $attributes

Return Value

$this

$this setValueNames(array $values)

Set the custom values on the validator.

Parameters

array $values

Return Value

$this

PresenceVerifierInterface getPresenceVerifier()

Get the Presence Verifier implementation.

void setPresenceVerifier(PresenceVerifierInterface $presenceVerifier)

Set the Presence Verifier implementation.

Parameters

PresenceVerifierInterface $presenceVerifier

Return Value

void

TranslatorInterface getTranslator()

Get the Translator implementation.

Return Value

TranslatorInterface

void setTranslator(TranslatorInterface $translator)

Set the Translator implementation.

Parameters

TranslatorInterface $translator

Return Value

void

array getCustomMessages()

Get the custom messages for the validator.

Return Value

array

void setCustomMessages(array $messages)

Set the custom messages for the validator.

Parameters

array $messages

Return Value

void

array getCustomAttributes()

Get the custom attributes used by the validator.

Return Value

array

$this addCustomAttributes(array $customAttributes)

Add custom attributes to the validator.

Parameters

array $customAttributes

Return Value

$this

array getCustomValues()

Get the custom values for the validator.

Return Value

array

$this addCustomValues(array $customValues)

Add the custom values for the validator.

Parameters

array $customValues

Return Value

$this

array getFallbackMessages()

Get the fallback messages for the validator.

Return Value

array

void setFallbackMessages(array $messages)

Set the fallback messages for the validator.

Parameters

array $messages

Return Value

void

array failed()

Get the failed validation rules.

Return Value

array

MessageBag messages()

Get the message container for the validator.

Return Value

MessageBag

MessageBag errors()

An alternative more semantic shortcut to the message container.

Return Value

MessageBag

MessageBag getMessageBag()

Get the messages for the instance.

Return Value

MessageBag

void setContainer(Container $container)

Set the IoC container instance.

Parameters

Container $container

Return Value

void

protected bool|null callExtension(string $rule, array $parameters)

Call a custom validator extension.

Parameters

string $rule
array $parameters

Return Value

bool|null

protected bool callClassBasedExtension(string $callback, array $parameters)

Call a class based validator extension.

Parameters

string $callback
array $parameters

Return Value

bool

protected string|null callReplacer(string $message, string $attribute, string $rule, array $parameters)

Call a custom validator message replacer.

Parameters

string $message
string $attribute
string $rule
array $parameters

Return Value

string|null

protected string callClassBasedReplacer(string $callback, string $message, string $attribute, string $rule, array $parameters)

Call a class based validator message replacer.

Parameters

string $callback
string $message
string $attribute
string $rule
array $parameters

Return Value

string

protected void requireParameterCount(int $count, array $parameters, string $rule)

Require a certain number of parameters to be present.

Parameters

int $count
array $parameters
string $rule

Return Value

void

Exceptions

InvalidArgumentException

protected bool compare(mixed $first, mixed $second, string $operator)

Determine if a comparison passes between the given values.

Parameters

mixed $first
mixed $second
string $operator

Return Value

bool

mixed __call(string $method, array $parameters)

Handle dynamic calls to class methods.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException