W3cubDocs

/Laravel 8

Validator

class Validator implements Validator (View source)

Traits

FormatsMessages
ValidatesAttributes
ReplacesAttributes

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.
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 $dotPlaceholder The current placeholder for dots in rule keys.

Methods

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

Replace all place-holders for the between rule.

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

Replace all place-holders for the date_format rule.

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

Replace all place-holders for the different rule.

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

Replace all place-holders for the digits rule.

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

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

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

Replace all place-holders for the min rule.

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

Replace all place-holders for the max rule.

from ReplacesAttributes
string replaceMultipleOf(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the multiple_of rule.

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

Replace all place-holders for the in rule.

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

Replace all place-holders for the not_in rule.

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

Replace all place-holders for the in_array rule.

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

Replace all place-holders for the mimetypes rule.

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

Replace all place-holders for the mimes rule.

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

Replace all place-holders for the required_with rule.

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

Replace all place-holders for the required_with_all rule.

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

Replace all place-holders for the required_without rule.

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

Replace all place-holders for the required_without_all rule.

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

Replace all place-holders for the size rule.

from ReplacesAttributes
string replaceGt(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the gt rule.

from ReplacesAttributes
string replaceLt(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the lt rule.

from ReplacesAttributes
string replaceGte(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the gte rule.

from ReplacesAttributes
string replaceLte(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the lte rule.

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

Replace all place-holders for the required_if rule.

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

Replace all place-holders for the required_unless rule.

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

Replace all place-holders for the same rule.

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

Replace all place-holders for the before rule.

from ReplacesAttributes
string replaceBeforeOrEqual(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the before_or_equal rule.

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

Replace all place-holders for the after rule.

from ReplacesAttributes
string replaceAfterOrEqual(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the after_or_equal rule.

from ReplacesAttributes
string replaceDateEquals(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the date_equals rule.

from ReplacesAttributes
string replaceDimensions(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the dimensions rule.

from ReplacesAttributes
string replaceEndsWith(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the ends_with rule.

from ReplacesAttributes
string replaceStartsWith(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the starts_with rule.

from ReplacesAttributes
string getMessage(string $attribute, string $rule)

Get the validation message for an attribute and rule.

from FormatsMessages
string|null getInlineMessage(string $attribute, string $rule)

Get the proper inline error message for standard and size rules.

from FormatsMessages
string|null getFromLocalArray(string $attribute, string $lowerRule, array|null $source = null)

Get the inline message for a rule if it exists.

from FormatsMessages
string getCustomMessageFromTranslator(string $key)

Get the custom error message from translator.

from FormatsMessages
string getWildcardCustomMessages(array $messages, string $search, string $default)

Check the given messages for a wildcard key.

from FormatsMessages
string getSizeMessage(string $attribute, string $rule)

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

from FormatsMessages
string getAttributeType(string $attribute)

Get the data type of the given attribute.

from FormatsMessages
string makeReplacements(string $message, string $attribute, string $rule, array $parameters)

Replace all error message place-holders with actual values.

from FormatsMessages
string getDisplayableAttribute(string $attribute)

Get the displayable name of the attribute.

from FormatsMessages
string getAttributeFromTranslations(string $name)

Get the given attribute from the attribute translations.

from FormatsMessages
string replaceAttributePlaceholder(string $message, string $value)

Replace the :attribute placeholder in the given message.

from FormatsMessages
string replaceInputPlaceholder(string $message, string $attribute)

Replace the :input placeholder in the given message.

from FormatsMessages
string getDisplayableValue(string $attribute, mixed $value)

Get the displayable name of the value.

from FormatsMessages
array getAttributeList(array $values)

Transform an array of attributes to their displayable form.

from FormatsMessages
string|null callReplacer(string $message, string $attribute, string $rule, array $parameters, Validator $validator)

Call a custom validator message replacer.

from FormatsMessages
string callClassBasedReplacer(string $callback, string $message, string $attribute, string $rule, array $parameters, Validator $validator)

Call a class based validator message replacer.

from FormatsMessages
bool validateAccepted(string $attribute, mixed $value)

Validate that an attribute was "accepted".

from ValidatesAttributes
bool validateActiveUrl(string $attribute, mixed $value)

Validate that an attribute is an active URL.

from ValidatesAttributes
bool validateBail()

"Break" on first validation fail.

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

Validate the date is before a given date.

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

Validate the date is before or equal a given date.

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

Validate the date is after a given date.

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

Validate the date is equal or after a given date.

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

Compare a given date against another using an operator.

from ValidatesAttributes
string|null getDateFormat(string $attribute)

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

from ValidatesAttributes
int getDateTimestamp(mixed $value)

Get the date timestamp.

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

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

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

Get a DateTime instance from a string.

from ValidatesAttributes
DateTime|null getDateTime(string $value)

Get a DateTime instance from a string with no format.

from ValidatesAttributes
bool validateAlpha(string $attribute, mixed $value)

Validate that an attribute contains only alphabetic characters.

from ValidatesAttributes
bool validateAlphaDash(string $attribute, mixed $value)

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

from ValidatesAttributes
bool validateAlphaNum(string $attribute, mixed $value)

Validate that an attribute contains only alpha-numeric characters.

from ValidatesAttributes
bool validateArray(string $attribute, mixed $value, array $parameters = [])

Validate that an attribute is an array.

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

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

from ValidatesAttributes
bool validateBoolean(string $attribute, mixed $value)

Validate that an attribute is a boolean.

from ValidatesAttributes
bool validateConfirmed(string $attribute, mixed $value)

Validate that an attribute has a matching confirmation.

from ValidatesAttributes
bool validateDate(string $attribute, mixed $value)

Validate that an attribute is a valid date.

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

Validate that an attribute matches a date format.

from ValidatesAttributes
bool validateDateEquals(string $attribute, mixed $value, array $parameters)

Validate that an attribute is equal to another date.

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

Validate that an attribute is different from another attribute.

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

Validate that an attribute has a given number of digits.

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

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

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

Validate the dimensions of an image matches the given values.

from ValidatesAttributes
bool failsBasicDimensionChecks(array $parameters, int $width, int $height)

Test if the given width and height fail any conditions.

from ValidatesAttributes
bool failsRatioCheck(array $parameters, int $width, int $height)

Determine if the given parameters fail a dimension ratio check.

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

Validate an attribute is unique among other values.

from ValidatesAttributes
array getDistinctValues(string $attribute)

Get the values to distinct between.

from ValidatesAttributes
array extractDistinctValues(string $attribute)

Extract the distinct values from the data.

from ValidatesAttributes
bool validateEmail(string $attribute, mixed $value, array $parameters)

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

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

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

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

Get the number of records that exist in storage.

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

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

from ValidatesAttributes
array getUniqueIds(string|null $idColumn, array $parameters)

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

from ValidatesAttributes
int prepareUniqueId(mixed $id)

Prepare the given ID for querying.

from ValidatesAttributes
array getUniqueExtra(array $parameters)

Get the extra conditions for a unique rule.

from ValidatesAttributes
array parseTable(string $table)

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

from ValidatesAttributes
bool getQueryColumn(array $parameters, string $attribute)

Get the column name for an exists / unique query.

from ValidatesAttributes
string guessColumnForQuery(string $attribute)

Guess the database column from the given attribute name.

from ValidatesAttributes
array getExtraConditions(array $segments)

Get the extra conditions for a unique / exists rule.

from ValidatesAttributes
bool validateFile(string $attribute, mixed $value)

Validate the given value is a valid file.

from ValidatesAttributes
bool validateFilled(string $attribute, mixed $value)

Validate the given attribute is filled if it is present.

from ValidatesAttributes
bool validateGt(string $attribute, mixed $value, array $parameters)

Validate that an attribute is greater than another attribute.

from ValidatesAttributes
bool validateLt(string $attribute, mixed $value, array $parameters)

Validate that an attribute is less than another attribute.

from ValidatesAttributes
bool validateGte(string $attribute, mixed $value, array $parameters)

Validate that an attribute is greater than or equal another attribute.

from ValidatesAttributes
bool validateLte(string $attribute, mixed $value, array $parameters)

Validate that an attribute is less than or equal another attribute.

from ValidatesAttributes
bool validateImage(string $attribute, mixed $value)

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

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

Validate an attribute is contained within a list of values.

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

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

from ValidatesAttributes
bool validateInteger(string $attribute, mixed $value)

Validate that an attribute is an integer.

from ValidatesAttributes
bool validateIp(string $attribute, mixed $value)

Validate that an attribute is a valid IP.

from ValidatesAttributes
bool validateIpv4(string $attribute, mixed $value)

Validate that an attribute is a valid IPv4.

from ValidatesAttributes
bool validateIpv6(string $attribute, mixed $value)

Validate that an attribute is a valid IPv6.

from ValidatesAttributes
bool validateJson(string $attribute, mixed $value)

Validate the attribute is a valid JSON string.

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

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

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

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

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

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

from ValidatesAttributes
bool shouldBlockPhpUpload(mixed $value, array $parameters)

Check if PHP uploads are explicitly allowed.

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

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

from ValidatesAttributes
bool validateMultipleOf(string $attribute, mixed $value, array $parameters)

Validate the value of an attribute is a multiple of a given value.

from ValidatesAttributes
bool validateNullable()

"Indicate" validation should pass if value is null.

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

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

from ValidatesAttributes
bool validateNumeric(string $attribute, mixed $value)

Validate that an attribute is numeric.

from ValidatesAttributes
bool validatePassword(string $attribute, mixed $value, array $parameters)

Validate that the current logged in user's password matches the given value.

from ValidatesAttributes
bool validatePresent(string $attribute, mixed $value)

Validate that an attribute exists even if not filled.

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

Validate that an attribute passes a regular expression check.

from ValidatesAttributes
bool validateNotRegex(string $attribute, mixed $value, array $parameters)

Validate that an attribute does not pass a regular expression check.

from ValidatesAttributes
bool validateRequired(string $attribute, mixed $value)

Validate that a required attribute exists.

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

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

from ValidatesAttributes
bool validateExcludeIf(string $attribute, mixed $value, mixed $parameters)

Indicate that an attribute should be excluded when another attribute has a given value.

from ValidatesAttributes
bool validateExcludeUnless(string $attribute, mixed $value, mixed $parameters)

Indicate that an attribute should be excluded when another attribute does not have a given value.

from ValidatesAttributes
bool validateExcludeWithout(string $attribute, mixed $value, mixed $parameters)

Indicate that an attribute should be excluded when another attribute is missing.

from ValidatesAttributes
array prepareValuesAndOther(array $parameters)

Prepare the values and the other value for validation.

from ValidatesAttributes
array convertValuesToBoolean(array $values)

Convert the given values to boolean if they are string "true" / "false".

from ValidatesAttributes
array convertValuesToNull(array $values)

Convert the given values to null if they are string "null".

from ValidatesAttributes
bool validateRequiredUnless(string $attribute, mixed $value, mixed $parameters)

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

from ValidatesAttributes
bool validateRequiredWith(string $attribute, mixed $value, mixed $parameters)

Validate that an attribute exists when any other attribute exists.

from ValidatesAttributes
bool validateRequiredWithAll(string $attribute, mixed $value, mixed $parameters)

Validate that an attribute exists when all other attributes exists.

from ValidatesAttributes
bool validateRequiredWithout(string $attribute, mixed $value, mixed $parameters)

Validate that an attribute exists when another attribute does not.

from ValidatesAttributes
bool validateRequiredWithoutAll(string $attribute, mixed $value, mixed $parameters)

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

from ValidatesAttributes
bool anyFailingRequired(array $attributes)

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

from ValidatesAttributes
bool allFailingRequired(array $attributes)

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

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

Validate that two attributes match.

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

Validate the size of an attribute.

from ValidatesAttributes
bool validateSometimes()

"Validate" optional attributes.

from ValidatesAttributes
bool validateStartsWith(string $attribute, mixed $value, array $parameters)

Validate the attribute starts with a given substring.

from ValidatesAttributes
bool validateEndsWith(string $attribute, mixed $value, array $parameters)

Validate the attribute ends with a given substring.

from ValidatesAttributes
bool validateString(string $attribute, mixed $value)

Validate that an attribute is a string.

from ValidatesAttributes
bool validateTimezone(string $attribute, mixed $value)

Validate that an attribute is a valid timezone.

from ValidatesAttributes
bool validateUrl(string $attribute, mixed $value)

Validate that an attribute is a valid URL.

from ValidatesAttributes
bool validateUuid(string $attribute, mixed $value)

Validate that an attribute is a valid UUID.

from ValidatesAttributes
mixed getSize(string $attribute, mixed $value)

Get the size of an attribute.

from ValidatesAttributes
bool isValidFileInstance(mixed $value)

Check that the given value is a valid file instance.

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

Determine if a comparison passes between the given values.

from ValidatesAttributes
array parseNamedParameters(array $parameters)

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

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

Require a certain number of parameters to be present.

from ValidatesAttributes
bool isSameType(mixed $first, mixed $second)

Check if the parameters are of the same type.

from ValidatesAttributes
void shouldBeNumeric(string $attribute, string $rule)

Adds the existing rule to the numericRules array if the attribute's value is numeric.

from ValidatesAttributes
void __construct(Translator $translator, array $data, array $rules, array $messages = [], array $customAttributes = [])

Create a new Validator instance.

array parseData(array $data)

Parse the data array, converting dots and asterisks.

array replacePlaceholders(array $data)

Replace the placeholders used in data keys.

string replacePlaceholderInString(string $value)

Replace the placeholders in the given string.

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

bool shouldBeExcluded(string $attribute)

Determine if the attribute should be excluded.

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.

array validated()

Get the attributes and values that were validated.

void validateAttribute(string $attribute, string $rule)

Validate a given attribute against a rule.

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 getPrimaryAttribute(string $attribute)

Get the primary attribute name.

array replaceAsterisksInParameters(array $parameters, array $keys)

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

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

Determine if the attribute is validatable.

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

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

bool isImplicit(object|string $rule)

Determine if a given rule implies the attribute is required.

bool passesOptionalCheck(string $attribute)

Determine if the attribute passes any optional check.

bool isNotNullIfMarkedAsNullable(string $rule, string $attribute)

Determine if the attribute fails the nullable check.

bool hasNotFailedPreviousRuleIfPresenceRule(string $rule, string $attribute)

Determine if it's a necessary presence validation.

void validateUsingCustomRule(string $attribute, mixed $value, Rule $rule)

Validate an attribute using a custom rule object.

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.

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.

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.

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.

array getRules()

Get the validation rules.

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

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 $customAttributes)

Add custom attributes to the validator.

$this setImplicitAttributesFormatter(callable $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.

Translator getTranslator()

Get the Translator implementation.

void setTranslator(Translator $translator)

Set the Translator implementation.

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.

mixed __call(string $method, array $parameters)

Handle dynamic calls to class methods.

Details

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 replaceMultipleOf(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the multiple_of 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 replaceGt(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the gt rule.

Parameters

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

Return Value

string

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

Replace all place-holders for the lt rule.

Parameters

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

Return Value

string

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

Replace all place-holders for the gte rule.

Parameters

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

Return Value

string

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

Replace all place-holders for the lte 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 replaceBeforeOrEqual(string $message, string $attribute, string $rule, array $parameters)

Replace all place-holders for the before_or_equal 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

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

Replace all place-holders for the after_or_equal rule.

Parameters

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

Return Value

string

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

Replace all place-holders for the date_equals rule.

Parameters

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

Return Value

string

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

Replace all place-holders for the dimensions rule.

Parameters

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

Return Value

string

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

Replace all place-holders for the ends_with rule.

Parameters

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

Return Value

string

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

Replace all place-holders for the starts_with rule.

Parameters

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

Return Value

string

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 $rule)

Get the proper inline error message for standard and size rules.

Parameters

string $attribute
string $rule

Return Value

string|null

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

Get the inline message for a rule if it exists.

Parameters

string $attribute
string $lowerRule
array|null $source

Return Value

string|null

protected string getCustomMessageFromTranslator(string $key)

Get the custom error message from translator.

Parameters

string $key

Return Value

string

protected string getWildcardCustomMessages(array $messages, string $search, string $default)

Check the given messages for a wildcard key.

Parameters

array $messages
string $search
string $default

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

string makeReplacements(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

string getDisplayableAttribute(string $attribute)

Get the displayable name of the attribute.

Parameters

string $attribute

Return Value

string

protected string getAttributeFromTranslations(string $name)

Get the given attribute from the attribute translations.

Parameters

string $name

Return Value

string

protected string replaceAttributePlaceholder(string $message, string $value)

Replace the :attribute placeholder in the given message.

Parameters

string $message
string $value

Return Value

string

protected string replaceInputPlaceholder(string $message, string $attribute)

Replace the :input placeholder in the given message.

Parameters

string $message
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 array getAttributeList(array $values)

Transform an array of attributes to their displayable form.

Parameters

array $values

Return Value

array

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

Call a custom validator message replacer.

Parameters

string $message
string $attribute
string $rule
array $parameters
Validator $validator

Return Value

string|null

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

Call a class based validator message replacer.

Parameters

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

Return Value

string

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

bool validateActiveUrl(string $attribute, mixed $value)

Validate that an attribute is an active URL.

Parameters

string $attribute
mixed $value

Return Value

bool

bool validateBail()

"Break" on first validation fail.

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

Return Value

bool

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

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

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

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 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 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 DateTime|null getDateTime(string $value)

Get a DateTime instance from a string with no format.

Parameters

string $value

Return Value

DateTime|null

bool validateAlpha(string $attribute, mixed $value)

Validate that an attribute contains only alphabetic characters.

Parameters

string $attribute
mixed $value

Return Value

bool

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

bool validateAlphaNum(string $attribute, mixed $value)

Validate that an attribute contains only alpha-numeric characters.

Parameters

string $attribute
mixed $value

Return Value

bool

bool validateArray(string $attribute, mixed $value, array $parameters = [])

Validate that an attribute is an array.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

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

bool validateBoolean(string $attribute, mixed $value)

Validate that an attribute is a boolean.

Parameters

string $attribute
mixed $value

Return Value

bool

bool validateConfirmed(string $attribute, mixed $value)

Validate that an attribute has a matching confirmation.

Parameters

string $attribute
mixed $value

Return Value

bool

bool validateDate(string $attribute, mixed $value)

Validate that an attribute is a valid date.

Parameters

string $attribute
mixed $value

Return Value

bool

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

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

Validate that an attribute is equal to another date.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

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

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

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

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 failsBasicDimensionChecks(array $parameters, int $width, int $height)

Test if the given width and height fail any conditions.

Parameters

array $parameters
int $width
int $height

Return Value

bool

protected bool failsRatioCheck(array $parameters, int $width, int $height)

Determine if the given parameters fail a dimension ratio check.

Parameters

array $parameters
int $width
int $height

Return Value

bool

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 array getDistinctValues(string $attribute)

Get the values to distinct between.

Parameters

string $attribute

Return Value

array

protected array extractDistinctValues(string $attribute)

Extract the distinct values from the data.

Parameters

string $attribute

Return Value

array

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

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

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

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

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 getUniqueIds(string|null $idColumn, array $parameters)

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

Parameters

string|null $idColumn
array $parameters

Return Value

array

protected int prepareUniqueId(mixed $id)

Prepare the given ID for querying.

Parameters

mixed $id

Return Value

int

protected array getUniqueExtra(array $parameters)

Get the extra conditions for a unique rule.

Parameters

array $parameters

Return Value

array

array parseTable(string $table)

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

Parameters

string $table

Return Value

array

bool getQueryColumn(array $parameters, string $attribute)

Get the column name for an exists / unique query.

Parameters

array $parameters
string $attribute

Return Value

bool

string guessColumnForQuery(string $attribute)

Guess the database column from the given attribute name.

Parameters

string $attribute

Return Value

string

protected array getExtraConditions(array $segments)

Get the extra conditions for a unique / exists rule.

Parameters

array $segments

Return Value

array

bool validateFile(string $attribute, mixed $value)

Validate the given value is a valid file.

Parameters

string $attribute
mixed $value

Return Value

bool

bool validateFilled(string $attribute, mixed $value)

Validate the given attribute is filled if it is present.

Parameters

string $attribute
mixed $value

Return Value

bool

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

Validate that an attribute is greater than another attribute.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

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

Validate that an attribute is less than another attribute.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

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

Validate that an attribute is greater than or equal another attribute.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

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

Validate that an attribute is less than or equal another attribute.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

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

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

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

bool validateInteger(string $attribute, mixed $value)

Validate that an attribute is an integer.

Parameters

string $attribute
mixed $value

Return Value

bool

bool validateIp(string $attribute, mixed $value)

Validate that an attribute is a valid IP.

Parameters

string $attribute
mixed $value

Return Value

bool

bool validateIpv4(string $attribute, mixed $value)

Validate that an attribute is a valid IPv4.

Parameters

string $attribute
mixed $value

Return Value

bool

bool validateIpv6(string $attribute, mixed $value)

Validate that an attribute is a valid IPv6.

Parameters

string $attribute
mixed $value

Return Value

bool

bool validateJson(string $attribute, mixed $value)

Validate the attribute is a valid JSON string.

Parameters

string $attribute
mixed $value

Return Value

bool

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

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

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 bool shouldBlockPhpUpload(mixed $value, array $parameters)

Check if PHP uploads are explicitly allowed.

Parameters

mixed $value
array $parameters

Return Value

bool

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

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

Validate the value of an attribute is a multiple of a given value.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

bool validateNullable()

"Indicate" validation should pass if value is null.

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

Return Value

bool

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

bool validateNumeric(string $attribute, mixed $value)

Validate that an attribute is numeric.

Parameters

string $attribute
mixed $value

Return Value

bool

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

Validate that the current logged in user's password matches the given value.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

bool validatePresent(string $attribute, mixed $value)

Validate that an attribute exists even if not filled.

Parameters

string $attribute
mixed $value

Return Value

bool

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

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

Validate that an attribute does not pass a regular expression check.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

bool validateRequired(string $attribute, mixed $value)

Validate that a required attribute exists.

Parameters

string $attribute
mixed $value

Return Value

bool

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

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

Indicate that an attribute should be excluded when another attribute has a given value.

Parameters

string $attribute
mixed $value
mixed $parameters

Return Value

bool

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

Indicate that an attribute should be excluded when another attribute does not have a given value.

Parameters

string $attribute
mixed $value
mixed $parameters

Return Value

bool

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

Indicate that an attribute should be excluded when another attribute is missing.

Parameters

string $attribute
mixed $value
mixed $parameters

Return Value

bool

protected array prepareValuesAndOther(array $parameters)

Prepare the values and the other value for validation.

Parameters

array $parameters

Return Value

array

protected array convertValuesToBoolean(array $values)

Convert the given values to boolean if they are string "true" / "false".

Parameters

array $values

Return Value

array

protected array convertValuesToNull(array $values)

Convert the given values to null if they are string "null".

Parameters

array $values

Return Value

array

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

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

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

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

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

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

Validate that two attributes match.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

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

Validate the size of an attribute.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

bool validateSometimes()

"Validate" optional attributes.

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

Return Value

bool

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

Validate the attribute starts with a given substring.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

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

Validate the attribute ends with a given substring.

Parameters

string $attribute
mixed $value
array $parameters

Return Value

bool

bool validateString(string $attribute, mixed $value)

Validate that an attribute is a string.

Parameters

string $attribute
mixed $value

Return Value

bool

bool validateTimezone(string $attribute, mixed $value)

Validate that an attribute is a valid timezone.

Parameters

string $attribute
mixed $value

Return Value

bool

bool validateUrl(string $attribute, mixed $value)

Validate that an attribute is a valid URL.

Parameters

string $attribute
mixed $value

Return Value

bool

bool validateUuid(string $attribute, mixed $value)

Validate that an attribute is a valid UUID.

Parameters

string $attribute
mixed $value

Return Value

bool

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

Get the size of an attribute.

Parameters

string $attribute
mixed $value

Return Value

mixed

bool isValidFileInstance(mixed $value)

Check that the given value is a valid file instance.

Parameters

mixed $value

Return Value

bool

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

Exceptions

InvalidArgumentException

array parseNamedParameters(array $parameters)

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

Parameters

array $parameters

Return Value

array

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 isSameType(mixed $first, mixed $second)

Check if the parameters are of the same type.

Parameters

mixed $first
mixed $second

Return Value

bool

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

Adds the existing rule to the numericRules array if the attribute's value is numeric.

Parameters

string $attribute
string $rule

Return Value

void

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

Create a new Validator instance.

Parameters

Translator $translator
array $data
array $rules
array $messages
array $customAttributes

Return Value

void

array parseData(array $data)

Parse the data array, converting dots and asterisks.

Parameters

array $data

Return Value

array

protected array replacePlaceholders(array $data)

Replace the placeholders used in data keys.

Parameters

array $data

Return Value

array

protected string replacePlaceholderInString(string $value)

Replace the placeholders in the given string.

Parameters

string $value

Return Value

string

$this after(callable|string $callback)

Add an after validation callback.

Parameters

callable|string $callback

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

protected bool shouldBeExcluded(string $attribute)

Determine if the attribute should be excluded.

Parameters

string $attribute

Return Value

bool

protected void removeAttribute(string $attribute)

Remove the given attribute.

Parameters

string $attribute

Return Value

void

array validate()

Run the validator's rules against its data.

Return Value

array

Exceptions

ValidationException

array validateWithBag(string $errorBag)

Run the validator's rules against its data.

Parameters

string $errorBag

Return Value

array

Exceptions

ValidationException

array validated()

Get the attributes and values that were validated.

Return Value

array

Exceptions

ValidationException

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

Validate a given attribute against a rule.

Parameters

string $attribute
string $rule

Return Value

void

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

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 bool isValidatable(object|string $rule, string $attribute, mixed $value)

Determine if the attribute is validatable.

Parameters

object|string $rule
string $attribute
mixed $value

Return Value

bool

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

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

Parameters

object|string $rule
string $attribute
mixed $value

Return Value

bool

protected bool isImplicit(object|string $rule)

Determine if a given rule implies the attribute is required.

Parameters

object|string $rule

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 $rule, string $attribute)

Determine if the attribute fails the nullable check.

Parameters

string $rule
string $attribute

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 validateUsingCustomRule(string $attribute, mixed $value, Rule $rule)

Validate an attribute using a custom rule object.

Parameters

string $attribute
mixed $value
Rule $rule

Return Value

void

protected bool shouldStopValidating(string $attribute)

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

Parameters

string $attribute

Return Value

bool

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 excludeAttribute(string $attribute)

Add the given attribute to the list of excluded attributes.

Parameters

string $attribute

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

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

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

array attributes()

Get the data under validation.

Return Value

array

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

protected mixed getValue(string $attribute)

Get the value of a given attribute.

Parameters

string $attribute

Return Value

mixed

array getRules()

Get the validation rules.

Return Value

array

$this setRules(array $rules)

Set the validation rules.

Parameters

array $rules

Return Value

$this

void addRules(array $rules)

Parse the given rules and merge them into current rules.

Parameters

array $rules

Return Value

void

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

Add conditions to a given field based on a Closure.

Parameters

string|array $attribute
string|array $rules
callable $callback

Return Value

$this

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 addDependentExtensions(array $extensions)

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

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

Register a custom dependent validator extension.

Parameters

string $rule
Closure|string $extension

Return Value

void

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

$this setCustomMessages(array $messages)

Set the custom messages for the validator.

Parameters

array $messages

Return Value

$this

$this setAttributeNames(array $attributes)

Set the custom attributes on the validator.

Parameters

array $attributes

Return Value

$this

$this addCustomAttributes(array $customAttributes)

Add custom attributes to the validator.

Parameters

array $customAttributes

Return Value

$this

$this setImplicitAttributesFormatter(callable $formatter = null)

Set the callback that used to format an implicit attribute.

.

Parameters

callable $formatter

Return Value

$this

$this setValueNames(array $values)

Set the custom values on the validator.

Parameters

array $values

Return Value

$this

$this addCustomValues(array $customValues)

Add the custom values for the validator.

Parameters

array $customValues

Return Value

$this

void setFallbackMessages(array $messages)

Set the fallback messages for the validator.

Parameters

array $messages

Return Value

void

PresenceVerifierInterface getPresenceVerifier(string|null $connection = null)

Get the Presence Verifier implementation.

Parameters

string|null $connection

Return Value

PresenceVerifierInterface

Exceptions

RuntimeException

void setPresenceVerifier(PresenceVerifierInterface $presenceVerifier)

Set the Presence Verifier implementation.

Parameters

PresenceVerifierInterface $presenceVerifier

Return Value

void

Translator getTranslator()

Get the Translator implementation.

Return Value

Translator

void setTranslator(Translator $translator)

Set the Translator implementation.

Parameters

Translator $translator

Return Value

void

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

mixed __call(string $method, array $parameters)

Handle dynamic calls to class methods.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/8.x/Illuminate/Validation/Validator.html