trait Illuminate / Validation / Concerns / ValidatesAttributes
You're browsing the documentation for an upcoming version of Laravel. The documentation and features of this release are subject to change.

ValidatesAttributes

Methods

public

validateAccepted ( $attribute , $value ) : bool

Validate that an attribute was "accepted".

Parameters

  • $attribute string
  • $value mixed
public

validateAcceptedIf ( $attribute , $value , $parameters ) : bool

Validate that an attribute was "accepted" when another attribute has a given value.

Parameters

  • $attribute string
  • $value mixed
  • $parameters mixed
public

validateDeclined ( $attribute , $value ) : bool

Validate that an attribute was "declined".

Parameters

  • $attribute string
  • $value mixed
public

validateDeclinedIf ( $attribute , $value , $parameters ) : bool

Validate that an attribute was "declined" when another attribute has a given value.

Parameters

  • $attribute string
  • $value mixed
  • $parameters mixed
public

validateActiveUrl ( $attribute , $value ) : bool

Validate that an attribute is an active URL.

Parameters

  • $attribute string
  • $value mixed
protected

getDnsRecords ( $hostname , $type ) : array|false

Get the DNS records for the given hostname.

Parameters

  • $hostname string
  • $type int
public

validateAscii ( $attribute , $value ) : bool

Validate that an attribute is 7 bit ASCII.

Parameters

  • $attribute string
  • $value mixed
public

validateBail ( ) : bool

"Break" on first validation fail.

public

validateBefore ( $attribute , $value , $parameters ) : bool

Validate the date is before a given date.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateBeforeOrEqual ( $attribute , $value , $parameters ) : bool

Validate the date is before or equal a given date.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateAfter ( $attribute , $value , $parameters ) : bool

Validate the date is after a given date.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateAfterOrEqual ( $attribute , $value , $parameters ) : bool

Validate the date is equal or after a given date.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
protected

compareDates ( $attribute , $value , $parameters , $operator ) : bool

Compare a given date against another using an operator.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
  • $operator string
protected

getDateFormat ( $attribute ) : string|null

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

Parameters

  • $attribute string
protected

getDateTimestamp ( $value ) : int

Get the date timestamp.

Parameters

  • $value mixed
protected

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

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

Parameters

  • $format string
  • $first string
  • $second string
  • $operator string
protected

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

Get a DateTime instance from a string.

Parameters

  • $format string
  • $value string
protected

getDateTime ( $value ) : DateTime |null

Get a DateTime instance from a string with no format.

Parameters

  • $value string
public

validateAlpha ( $attribute , $value , $parameters ) : bool

Validate that an attribute contains only alphabetic characters.

Parameters

  • $attribute string
  • $value mixed
public

validateAlphaDash ( $attribute , $value , $parameters ) : bool

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

Parameters

  • $attribute string
  • $value mixed
public

validateAlphaNum ( $attribute , $value , $parameters ) : bool

Validate that an attribute contains only alpha-numeric characters.

Parameters

  • $attribute string
  • $value mixed
public

validateArray ( $attribute , $value , $parameters ) : bool

Validate that an attribute is an array.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateRequiredArrayKeys ( $attribute , $value , $parameters ) : bool

Validate that an array has all of the given keys.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateBetween ( $attribute , $value , $parameters ) : bool

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

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateBoolean ( $attribute , $value ) : bool

Validate that an attribute is a boolean.

Parameters

  • $attribute string
  • $value mixed
public

validateConfirmed ( $attribute , $value ) : bool

Validate that an attribute has a matching confirmation.

Parameters

  • $attribute string
  • $value mixed
protected

validateCurrentPassword ( $attribute , $value , $parameters ) : bool

Validate that the password of the currently authenticated user matches the given value.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateDate ( $attribute , $value ) : bool

Validate that an attribute is a valid date.

Parameters

  • $attribute string
  • $value mixed
public

validateDateFormat ( $attribute , $value , $parameters ) : bool

Validate that an attribute matches a date format.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateDateEquals ( $attribute , $value , $parameters ) : bool

Validate that an attribute is equal to another date.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateDecimal ( $attribute , $value , $parameters ) : bool

Validate that an attribute has a given number of decimal places.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateDifferent ( $attribute , $value , $parameters ) : bool

Validate that an attribute is different from another attribute.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateDigits ( $attribute , $value , $parameters ) : bool

Validate that an attribute has a given number of digits.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateDigitsBetween ( $attribute , $value , $parameters ) : bool

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

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateDimensions ( $attribute , $value , $parameters ) : bool

Validate the dimensions of an image matches the given values.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
protected

failsBasicDimensionChecks ( $parameters , $width , $height ) : bool

Test if the given width and height fail any conditions.

Parameters

  • $parameters array
  • $width int
  • $height int
protected

failsRatioCheck ( $parameters , $width , $height ) : bool

Determine if the given parameters fail a dimension ratio check.

Parameters

  • $parameters array
  • $width int
  • $height int
public

validateDistinct ( $attribute , $value , $parameters ) : bool

Validate an attribute is unique among other values.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
protected

getDistinctValues ( $attribute ) : array

Get the values to distinct between.

Parameters

  • $attribute string
protected

extractDistinctValues ( $attribute ) : array

Extract the distinct values from the data.

Parameters

  • $attribute string
public

validateEmail ( $attribute , $value , $parameters ) : bool

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

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateExists ( $attribute , $value , $parameters ) : bool

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

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
protected

getExistCount ( $connection , $table , $column , $value , $parameters ) : int

Get the number of records that exist in storage.

Parameters

  • $connection mixed
  • $table string
  • $column string
  • $value mixed
  • $parameters array|string>
public

validateUnique ( $attribute , $value , $parameters ) : bool

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

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
protected

getUniqueIds ( $idColumn , $parameters ) : array

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

Parameters

  • $idColumn string|null
  • $parameters array|string>
protected

prepareUniqueId ( $id ) : int

Prepare the given ID for querying.

Parameters

  • $id mixed
protected

getUniqueExtra ( $parameters ) : array

Get the extra conditions for a unique rule.

Parameters

  • $parameters array|string>
public

parseTable ( $table ) : array

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

Parameters

  • $table string
public

getQueryColumn ( $parameters , $attribute ) : bool

Get the column name for an exists / unique query.

Parameters

  • $parameters array|string>
  • $attribute string
public

guessColumnForQuery ( $attribute ) : string

Guess the database column from the given attribute name.

Parameters

  • $attribute string
protected

getExtraConditions ( array $segments ) : array

Get the extra conditions for a unique / exists rule.

Parameters

  • $segments array
public

validateFile ( $attribute , $value ) : bool

Validate the given value is a valid file.

Parameters

  • $attribute string
  • $value mixed
public

validateFilled ( $attribute , $value ) : bool

Validate the given attribute is filled if it is present.

Parameters

  • $attribute string
  • $value mixed
public

validateGt ( $attribute , $value , $parameters ) : bool

Validate that an attribute is greater than another attribute.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateLt ( $attribute , $value , $parameters ) : bool

Validate that an attribute is less than another attribute.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateGte ( $attribute , $value , $parameters ) : bool

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

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateLte ( $attribute , $value , $parameters ) : bool

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

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateLowercase ( $attribute , $value , $parameters ) : bool

Validate that an attribute is lowercase.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateUppercase ( $attribute , $value , $parameters ) : bool

Validate that an attribute is uppercase.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateImage ( $attribute , $value ) : bool

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

Parameters

  • $attribute string
  • $value mixed
public

validateIn ( $attribute , $value , $parameters ) : bool

Validate an attribute is contained within a list of values.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateInArray ( $attribute , $value , $parameters ) : bool

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

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateInteger ( $attribute , $value ) : bool

Validate that an attribute is an integer.

Parameters

  • $attribute string
  • $value mixed
public

validateIp ( $attribute , $value ) : bool

Validate that an attribute is a valid IP.

Parameters

  • $attribute string
  • $value mixed
public

validateIpv4 ( $attribute , $value ) : bool

Validate that an attribute is a valid IPv4.

Parameters

  • $attribute string
  • $value mixed
public

validateIpv6 ( $attribute , $value ) : bool

Validate that an attribute is a valid IPv6.

Parameters

  • $attribute string
  • $value mixed
public

validateMacAddress ( $attribute , $value ) : bool

Validate that an attribute is a valid MAC address.

Parameters

  • $attribute string
  • $value mixed
public

validateJson ( $attribute , $value ) : bool

Validate the attribute is a valid JSON string.

Parameters

  • $attribute string
  • $value mixed
public

validateMax ( $attribute , $value , $parameters ) : bool

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

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateMaxDigits ( $attribute , $value , $parameters ) : bool

Validate that an attribute has a maximum number of digits.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateMimes ( $attribute , $value , $parameters ) : bool

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

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateMimetypes ( $attribute , $value , $parameters ) : bool

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

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
protected

shouldBlockPhpUpload ( $value , $parameters ) : bool

Check if PHP uploads are explicitly allowed.

Parameters

  • $value mixed
  • $parameters array|string>
public

validateMin ( $attribute , $value , $parameters ) : bool

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

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateMinDigits ( $attribute , $value , $parameters ) : bool

Validate that an attribute has a minimum number of digits.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateMissing ( $attribute , $value , $parameters ) : bool

Validate that an attribute is missing.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateMissingIf ( $attribute , $value , $parameters ) : bool

Validate that an attribute is missing when another attribute has a given value.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateMissingUnless ( $attribute , $value , $parameters ) : bool

Validate that an attribute is missing unless another attribute has a given value.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateMissingWith ( $attribute , $value , $parameters ) : bool

Validate that an attribute is missing when any given attribute is present.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateMissingWithAll ( $attribute , $value , $parameters ) : bool

Validate that an attribute is missing when all given attributes are present.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateMultipleOf ( $attribute , $value , $parameters ) : bool

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

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateNullable ( ) : bool

"Indicate" validation should pass if value is null.

public

validateNotIn ( $attribute , $value , $parameters ) : bool

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

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateNumeric ( $attribute , $value ) : bool

Validate that an attribute is numeric.

Parameters

  • $attribute string
  • $value mixed
public

validatePresent ( $attribute , $value ) : bool

Validate that an attribute exists even if not filled.

Parameters

  • $attribute string
  • $value mixed
public

validateRegex ( $attribute , $value , $parameters ) : bool

Validate that an attribute passes a regular expression check.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateNotRegex ( $attribute , $value , $parameters ) : bool

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

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateRequired ( $attribute , $value ) : bool

Validate that a required attribute exists.

Parameters

  • $attribute string
  • $value mixed
public

validateRequiredIf ( $attribute , $value , $parameters ) : bool

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

Parameters

  • $attribute string
  • $value mixed
  • $parameters mixed
public

validateRequiredIfAccepted ( $attribute , $value , $parameters ) : bool

Validate that an attribute exists when another attribute was "accepted".

Parameters

  • $attribute string
  • $value mixed
  • $parameters mixed
public

validateProhibited ( $attribute , $value ) : bool

Validate that an attribute does not exist or is an empty string.

Parameters

  • $attribute string
  • $value mixed
public

validateProhibitedIf ( $attribute , $value , $parameters ) : bool

Validate that an attribute does not exist when another attribute has a given value.

Parameters

  • $attribute string
  • $value mixed
  • $parameters mixed
public

validateProhibitedUnless ( $attribute , $value , $parameters ) : bool

Validate that an attribute does not exist unless another attribute has a given value.

Parameters

  • $attribute string
  • $value mixed
  • $parameters mixed
public

validateProhibits ( $attribute , $value , $parameters ) : bool

Validate that other attributes do not exist when this attribute exists.

Parameters

  • $attribute string
  • $value mixed
  • $parameters mixed
public

validateExclude ( ) : bool

Indicate that an attribute is excluded.

public

validateExcludeIf ( $attribute , $value , $parameters ) : bool

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

Parameters

  • $attribute string
  • $value mixed
  • $parameters mixed
public

validateExcludeUnless ( $attribute , $value , $parameters ) : bool

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

Parameters

  • $attribute string
  • $value mixed
  • $parameters mixed
public

validateRequiredUnless ( $attribute , $value , $parameters ) : bool

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

Parameters

  • $attribute string
  • $value mixed
  • $parameters mixed
public

validateExcludeWith ( $attribute , $value , $parameters ) : bool

Indicate that an attribute should be excluded when another attribute presents.

Parameters

  • $attribute string
  • $value mixed
  • $parameters mixed
public

validateExcludeWithout ( $attribute , $value , $parameters ) : bool

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

Parameters

  • $attribute string
  • $value mixed
  • $parameters mixed
public

parseDependentRuleParameters ( $parameters ) : array

Prepare the values and the other value for validation.

Parameters

  • $parameters array|string>
protected

shouldConvertToBoolean ( $parameter ) : bool

Check if parameter should be converted to boolean.

Parameters

  • $parameter string
protected

convertValuesToBoolean ( $values ) : array

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

Parameters

  • $values array
protected

convertValuesToNull ( $values ) : array

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

Parameters

  • $values array
public

validateRequiredWith ( $attribute , $value , $parameters ) : bool

Validate that an attribute exists when any other attribute exists.

Parameters

  • $attribute string
  • $value mixed
  • $parameters mixed
public

validateRequiredWithAll ( $attribute , $value , $parameters ) : bool

Validate that an attribute exists when all other attributes exist.

Parameters

  • $attribute string
  • $value mixed
  • $parameters mixed
public

validateRequiredWithout ( $attribute , $value , $parameters ) : bool

Validate that an attribute exists when another attribute does not.

Parameters

  • $attribute string
  • $value mixed
  • $parameters mixed
public

validateRequiredWithoutAll ( $attribute , $value , $parameters ) : bool

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

Parameters

  • $attribute string
  • $value mixed
  • $parameters mixed
protected

anyFailingRequired ( array $attributes ) : bool

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

Parameters

  • $attributes array
protected

allFailingRequired ( array $attributes ) : bool

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

Parameters

  • $attributes array
public

validateSame ( $attribute , $value , $parameters ) : bool

Validate that two attributes match.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateSize ( $attribute , $value , $parameters ) : bool

Validate the size of an attribute.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateSometimes ( ) : bool

"Validate" optional attributes.

public

validateStartsWith ( $attribute , $value , $parameters ) : bool

Validate the attribute starts with a given substring.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateDoesntStartWith ( $attribute , $value , $parameters ) : bool

Validate the attribute does not start with a given substring.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateEndsWith ( $attribute , $value , $parameters ) : bool

Validate the attribute ends with a given substring.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateDoesntEndWith ( $attribute , $value , $parameters ) : bool

Validate the attribute does not end with a given substring.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateString ( $attribute , $value ) : bool

Validate that an attribute is a string.

Parameters

  • $attribute string
  • $value mixed
public

validateTimezone ( $attribute , $value , $parameters ) : bool

Validate that an attribute is a valid timezone.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array|string>
public

validateUrl ( $attribute , $value , $parameters ) : bool

Validate that an attribute is a valid URL.

Parameters

  • $attribute string
  • $value mixed
  • $parameters array
public

validateUlid ( $attribute , $value ) : bool

Validate that an attribute is a valid ULID.

Parameters

  • $attribute string
  • $value mixed
public

validateUuid ( $attribute , $value ) : bool

Validate that an attribute is a valid UUID.

Parameters

  • $attribute string
  • $value mixed
protected

getSize ( $attribute , $value ) : int|float|string

Get the size of an attribute.

Parameters

  • $attribute string
  • $value mixed
public

isValidFileInstance ( $value ) : bool

Check that the given value is a valid file instance.

Parameters

  • $value mixed
protected

compare ( $first , $second , $operator ) : bool

Determine if a comparison passes between the given values.

Parameters

  • $first mixed
  • $second mixed
  • $operator string
public

parseNamedParameters ( $parameters ) : array

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

Parameters

  • $parameters array|string>
public

requireParameterCount ( $count , $parameters , $rule ) : void

Require a certain number of parameters to be present.

Parameters

  • $count int
  • $parameters array|string>
  • $rule string
protected

isSameType ( $first , $second ) : bool

Check if the parameters are of the same type.

Parameters

  • $first mixed
  • $second mixed
protected

shouldBeNumeric ( $attribute , $rule ) : void

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

Parameters

  • $attribute string
  • $rule string
protected

trim ( $value ) : mixed

Trim the value if it is a string.

Parameters

  • $value mixed
protected

ensureExponentWithinAllowedRange ( $attribute , $value ) : mixed

Ensure the exponent is within the allowed range.

Parameters

  • $attribute string
  • $value mixed