ValidatesAttributes
trait ValidatesAttributes (View source)
Methods
bool | validateAccepted(string $attribute, mixed $value) Validate that an attribute was "accepted". | |
bool | validateActiveUrl(string $attribute, mixed $value) Validate that an attribute is an active URL. | |
bool | validateBail() "Break" on first validation fail. | |
bool | validateBefore(string $attribute, mixed $value, array $parameters) Validate the date is before a given date. | |
bool | validateBeforeOrEqual(string $attribute, mixed $value, array $parameters) Validate the date is before or equal a given date. | |
bool | validateAfter(string $attribute, mixed $value, array $parameters) Validate the date is after a given date. | |
bool | validateAfterOrEqual(string $attribute, mixed $value, array $parameters) Validate the date is equal or after a given date. | |
bool | compareDates(string $attribute, mixed $value, array $parameters, string $operator) Compare a given date against another using an operator. | |
string|null | getDateFormat(string $attribute) Get the date format for an attribute if it has one. | |
int | getDateTimestamp(mixed $value) Get the date timestamp. | |
bool | checkDateTimeOrder(string $format, string $first, string $second, string $operator) Given two date/time strings, check that one is after the other. | |
DateTime|null | getDateTimeWithOptionalFormat(string $format, string $value) Get a DateTime instance from a string. | |
DateTime|null | getDateTime(string $value) Get a DateTime instance from a string with no format. | |
bool | isTestingRelativeDateTime(mixed $value) Check if the given value should be adjusted to Carbon::getTestNow(). | |
bool | validateAlpha(string $attribute, mixed $value) Validate that an attribute contains only alphabetic characters. | |
bool | validateAlphaDash(string $attribute, mixed $value) Validate that an attribute contains only alpha-numeric characters, dashes, and underscores. | |
bool | validateAlphaNum(string $attribute, mixed $value) Validate that an attribute contains only alpha-numeric characters. | |
bool | validateArray(string $attribute, mixed $value, array $parameters = []) Validate that an attribute is an array. | |
bool | validateBetween(string $attribute, mixed $value, array $parameters) Validate the size of an attribute is between a set of values. | |
bool | validateBoolean(string $attribute, mixed $value) Validate that an attribute is a boolean. | |
bool | validateConfirmed(string $attribute, mixed $value) Validate that an attribute has a matching confirmation. | |
bool | validateDate(string $attribute, mixed $value) Validate that an attribute is a valid date. | |
bool | validateDateFormat(string $attribute, mixed $value, array $parameters) Validate that an attribute matches a date format. | |
bool | validateDateEquals(string $attribute, mixed $value, array $parameters) Validate that an attribute is equal to another date. | |
bool | validateDifferent(string $attribute, mixed $value, array $parameters) Validate that an attribute is different from another attribute. | |
bool | validateDigits(string $attribute, mixed $value, array $parameters) Validate that an attribute has a given number of digits. | |
bool | validateDigitsBetween(string $attribute, mixed $value, array $parameters) Validate that an attribute is between a given number of digits. | |
bool | validateDimensions(string $attribute, mixed $value, array $parameters) Validate the dimensions of an image matches the given values. | |
bool | failsBasicDimensionChecks(array $parameters, int $width, int $height) Test if the given width and height fail any conditions. | |
bool | failsRatioCheck(array $parameters, int $width, int $height) Determine if the given parameters fail a dimension ratio check. | |
bool | validateDistinct(string $attribute, mixed $value, array $parameters) Validate an attribute is unique among other values. | |
array | getDistinctValues(string $attribute) Get the values to distinct between. | |
array | extractDistinctValues(string $attribute) Extract the distinct values from the data. | |
bool | validateEmail(string $attribute, mixed $value, array $parameters) Validate that an attribute is a valid e-mail address. | |
bool | validateExists(string $attribute, mixed $value, array $parameters) Validate the existence of an attribute value in a database table. | |
int | getExistCount(mixed $connection, string $table, string $column, mixed $value, array $parameters) Get the number of records that exist in storage. | |
bool | validateUnique(string $attribute, mixed $value, array $parameters) Validate the uniqueness of an attribute value on a given database table. | |
array | getUniqueIds(string|null $idColumn, array $parameters) Get the excluded ID column and value for the unique rule. | |
int | prepareUniqueId(mixed $id) Prepare the given ID for querying. | |
array | getUniqueExtra(array $parameters) Get the extra conditions for a unique rule. | |
array | parseTable(string $table) Parse the connection / table for the unique / exists rules. | |
bool | getQueryColumn(array $parameters, string $attribute) Get the column name for an exists / unique query. | |
string | guessColumnForQuery(string $attribute) Guess the database column from the given attribute name. | |
array | getExtraConditions(array $segments) Get the extra conditions for a unique / exists rule. | |
bool | validateFile(string $attribute, mixed $value) Validate the given value is a valid file. | |
bool | validateFilled(string $attribute, mixed $value) Validate the given attribute is filled if it is present. | |
bool | validateGt(string $attribute, mixed $value, array $parameters) Validate that an attribute is greater than another attribute. | |
bool | validateLt(string $attribute, mixed $value, array $parameters) Validate that an attribute is less than another attribute. | |
bool | validateGte(string $attribute, mixed $value, array $parameters) Validate that an attribute is greater than or equal another attribute. | |
bool | validateLte(string $attribute, mixed $value, array $parameters) Validate that an attribute is less than or equal another attribute. | |
bool | validateImage(string $attribute, mixed $value) Validate the MIME type of a file is an image MIME type. | |
bool | validateIn(string $attribute, mixed $value, array $parameters) Validate an attribute is contained within a list of values. | |
bool | validateInArray(string $attribute, mixed $value, array $parameters) Validate that the values of an attribute is in another attribute. | |
bool | validateInteger(string $attribute, mixed $value) Validate that an attribute is an integer. | |
bool | validateIp(string $attribute, mixed $value) Validate that an attribute is a valid IP. | |
bool | validateIpv4(string $attribute, mixed $value) Validate that an attribute is a valid IPv4. | |
bool | validateIpv6(string $attribute, mixed $value) Validate that an attribute is a valid IPv6. | |
bool | validateJson(string $attribute, mixed $value) Validate the attribute is a valid JSON string. | |
bool | validateMax(string $attribute, mixed $value, array $parameters) Validate the size of an attribute is less than a maximum value. | |
bool | validateMimes(string $attribute, mixed $value, array $parameters) Validate the guessed extension of a file upload is in a set of file extensions. | |
bool | validateMimetypes(string $attribute, mixed $value, array $parameters) Validate the MIME type of a file upload attribute is in a set of MIME types. | |
bool | shouldBlockPhpUpload(mixed $value, array $parameters) Check if PHP uploads are explicitly allowed. | |
bool | validateMin(string $attribute, mixed $value, array $parameters) Validate the size of an attribute is greater than a minimum value. | |
bool | validateNullable() "Indicate" validation should pass if value is null. | |
bool | validateNotIn(string $attribute, mixed $value, array $parameters) Validate an attribute is not contained within a list of values. | |
bool | validateNumeric(string $attribute, mixed $value) Validate that an attribute is numeric. | |
bool | validatePassword(string $attribute, mixed $value, array $parameters) Validate that the current logged in user's password matches the given value. | |
bool | validatePresent(string $attribute, mixed $value) Validate that an attribute exists even if not filled. | |
bool | validateRegex(string $attribute, mixed $value, array $parameters) Validate that an attribute passes a regular expression check. | |
bool | validateNotRegex(string $attribute, mixed $value, array $parameters) Validate that an attribute does not pass a regular expression check. | |
bool | validateRequired(string $attribute, mixed $value) Validate that a required attribute exists. | |
bool | validateRequiredIf(string $attribute, mixed $value, mixed $parameters) Validate that an attribute exists when another attribute has a given value. | |
bool | validateExcludeIf(string $attribute, mixed $value, mixed $parameters) Indicate that an attribute should be excluded when another attribute has a given value. | |
bool | validateExcludeUnless(string $attribute, mixed $value, mixed $parameters) Indicate that an attribute should be excluded when another attribute does not have a given value. | |
bool | validateExcludeWithout(string $attribute, mixed $value, mixed $parameters) Indicate that an attribute should be excluded when another attribute is missing. | |
array | prepareValuesAndOther(array $parameters) Prepare the values and the other value for validation. | |
array | convertValuesToBoolean(array $values) Convert the given values to boolean if they are string "true" / "false". | |
bool | validateRequiredUnless(string $attribute, mixed $value, mixed $parameters) Validate that an attribute exists when another attribute does not have a given value. | |
bool | validateRequiredWith(string $attribute, mixed $value, mixed $parameters) Validate that an attribute exists when any other attribute exists. | |
bool | validateRequiredWithAll(string $attribute, mixed $value, mixed $parameters) Validate that an attribute exists when all other attributes exists. | |
bool | validateRequiredWithout(string $attribute, mixed $value, mixed $parameters) Validate that an attribute exists when another attribute does not. | |
bool | validateRequiredWithoutAll(string $attribute, mixed $value, mixed $parameters) Validate that an attribute exists when all other attributes do not. | |
bool | anyFailingRequired(array $attributes) Determine if any of the given attributes fail the required test. | |
bool | allFailingRequired(array $attributes) Determine if all of the given attributes fail the required test. | |
bool | validateSame(string $attribute, mixed $value, array $parameters) Validate that two attributes match. | |
bool | validateSize(string $attribute, mixed $value, array $parameters) Validate the size of an attribute. | |
bool | validateSometimes() "Validate" optional attributes. | |
bool | validateStartsWith(string $attribute, mixed $value, array $parameters) Validate the attribute starts with a given substring. | |
bool | validateEndsWith(string $attribute, mixed $value, array $parameters) Validate the attribute ends with a given substring. | |
bool | validateString(string $attribute, mixed $value) Validate that an attribute is a string. | |
bool | validateTimezone(string $attribute, mixed $value) Validate that an attribute is a valid timezone. | |
bool | validateUrl(string $attribute, mixed $value) Validate that an attribute is a valid URL. | |
bool | validateUuid(string $attribute, mixed $value) Validate that an attribute is a valid UUID. | |
mixed | getSize(string $attribute, mixed $value) Get the size of an attribute. | |
bool | isValidFileInstance(mixed $value) Check that the given value is a valid file instance. | |
bool | compare(mixed $first, mixed $second, string $operator) Determine if a comparison passes between the given values. | |
array | parseNamedParameters(array $parameters) Parse named parameters to $key => $value items. | |
void | requireParameterCount(int $count, array $parameters, string $rule) Require a certain number of parameters to be present. | |
bool | isSameType(mixed $first, mixed $second) Check if the parameters are of the same type. | |
void | shouldBeNumeric(string $attribute, string $rule) Adds the existing rule to the numericRules array if the attribute's value is numeric. |
Details
bool validateAccepted(string $attribute, mixed $value)
Validate that an attribute was "accepted".
This validation rule implies the attribute is "required".
bool validateActiveUrl(string $attribute, mixed $value)
Validate that an attribute is an active URL.
bool validateBail()
"Break" on first validation fail.
Always returns true, just lets us put "bail" in rules.
bool validateBefore(string $attribute, mixed $value, array $parameters)
Validate the date is before a given date.
bool validateBeforeOrEqual(string $attribute, mixed $value, array $parameters)
Validate the date is before or equal a given date.
bool validateAfter(string $attribute, mixed $value, array $parameters)
Validate the date is after a given date.
bool validateAfterOrEqual(string $attribute, mixed $value, array $parameters)
Validate the date is equal or after a given date.
protected bool compareDates(string $attribute, mixed $value, array $parameters, string $operator)
Compare a given date against another using an operator.
protected string|null getDateFormat(string $attribute)
Get the date format for an attribute if it has one.
protected int getDateTimestamp(mixed $value)
Get the date timestamp.
protected bool checkDateTimeOrder(string $format, string $first, string $second, string $operator)
Given two date/time strings, check that one is after the other.
protected DateTime|null getDateTimeWithOptionalFormat(string $format, string $value)
Get a DateTime instance from a string.
protected DateTime|null getDateTime(string $value)
Get a DateTime instance from a string with no format.
protected bool isTestingRelativeDateTime(mixed $value)
Check if the given value should be adjusted to Carbon::getTestNow().
bool validateAlpha(string $attribute, mixed $value)
Validate that an attribute contains only alphabetic characters.
bool validateAlphaDash(string $attribute, mixed $value)
Validate that an attribute contains only alpha-numeric characters, dashes, and underscores.
bool validateAlphaNum(string $attribute, mixed $value)
Validate that an attribute contains only alpha-numeric characters.
bool validateArray(string $attribute, mixed $value, array $parameters = [])
Validate that an attribute is an array.
bool validateBetween(string $attribute, mixed $value, array $parameters)
Validate the size of an attribute is between a set of values.
bool validateBoolean(string $attribute, mixed $value)
Validate that an attribute is a boolean.
bool validateConfirmed(string $attribute, mixed $value)
Validate that an attribute has a matching confirmation.
bool validateDate(string $attribute, mixed $value)
Validate that an attribute is a valid date.
bool validateDateFormat(string $attribute, mixed $value, array $parameters)
Validate that an attribute matches a date format.
bool validateDateEquals(string $attribute, mixed $value, array $parameters)
Validate that an attribute is equal to another date.
bool validateDifferent(string $attribute, mixed $value, array $parameters)
Validate that an attribute is different from another attribute.
bool validateDigits(string $attribute, mixed $value, array $parameters)
Validate that an attribute has a given number of digits.
bool validateDigitsBetween(string $attribute, mixed $value, array $parameters)
Validate that an attribute is between a given number of digits.
bool validateDimensions(string $attribute, mixed $value, array $parameters)
Validate the dimensions of an image matches the given values.
protected bool failsBasicDimensionChecks(array $parameters, int $width, int $height)
Test if the given width and height fail any conditions.
protected bool failsRatioCheck(array $parameters, int $width, int $height)
Determine if the given parameters fail a dimension ratio check.
bool validateDistinct(string $attribute, mixed $value, array $parameters)
Validate an attribute is unique among other values.
protected array getDistinctValues(string $attribute)
Get the values to distinct between.
protected array extractDistinctValues(string $attribute)
Extract the distinct values from the data.
bool validateEmail(string $attribute, mixed $value, array $parameters)
Validate that an attribute is a valid e-mail address.
bool validateExists(string $attribute, mixed $value, array $parameters)
Validate the existence of an attribute value in a database table.
protected int getExistCount(mixed $connection, string $table, string $column, mixed $value, array $parameters)
Get the number of records that exist in storage.
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.
protected array getUniqueIds(string|null $idColumn, array $parameters)
Get the excluded ID column and value for the unique rule.
protected int prepareUniqueId(mixed $id)
Prepare the given ID for querying.
protected array getUniqueExtra(array $parameters)
Get the extra conditions for a unique rule.
array parseTable(string $table)
Parse the connection / table for the unique / exists rules.
bool getQueryColumn(array $parameters, string $attribute)
Get the column name for an exists / unique query.
string guessColumnForQuery(string $attribute)
Guess the database column from the given attribute name.
protected array getExtraConditions(array $segments)
Get the extra conditions for a unique / exists rule.
bool validateFile(string $attribute, mixed $value)
Validate the given value is a valid file.
bool validateFilled(string $attribute, mixed $value)
Validate the given attribute is filled if it is present.
bool validateGt(string $attribute, mixed $value, array $parameters)
Validate that an attribute is greater than another attribute.
bool validateLt(string $attribute, mixed $value, array $parameters)
Validate that an attribute is less than another attribute.
bool validateGte(string $attribute, mixed $value, array $parameters)
Validate that an attribute is greater than or equal another attribute.
bool validateLte(string $attribute, mixed $value, array $parameters)
Validate that an attribute is less than or equal another attribute.
bool validateImage(string $attribute, mixed $value)
Validate the MIME type of a file is an image MIME type.
bool validateIn(string $attribute, mixed $value, array $parameters)
Validate an attribute is contained within a list of values.
bool validateInArray(string $attribute, mixed $value, array $parameters)
Validate that the values of an attribute is in another attribute.
bool validateInteger(string $attribute, mixed $value)
Validate that an attribute is an integer.
bool validateIp(string $attribute, mixed $value)
Validate that an attribute is a valid IP.
bool validateIpv4(string $attribute, mixed $value)
Validate that an attribute is a valid IPv4.
bool validateIpv6(string $attribute, mixed $value)
Validate that an attribute is a valid IPv6.
bool validateJson(string $attribute, mixed $value)
Validate the attribute is a valid JSON string.
bool validateMax(string $attribute, mixed $value, array $parameters)
Validate the size of an attribute is less than a maximum value.
bool validateMimes(string $attribute, mixed $value, array $parameters)
Validate the guessed extension of a file upload is in a set of file extensions.
bool validateMimetypes(string $attribute, mixed $value, array $parameters)
Validate the MIME type of a file upload attribute is in a set of MIME types.
protected bool shouldBlockPhpUpload(mixed $value, array $parameters)
Check if PHP uploads are explicitly allowed.
bool validateMin(string $attribute, mixed $value, array $parameters)
Validate the size of an attribute is greater than a minimum value.
bool validateNullable()
"Indicate" validation should pass if value is null.
Always returns true, just lets us put "nullable" in rules.
bool validateNotIn(string $attribute, mixed $value, array $parameters)
Validate an attribute is not contained within a list of values.
bool validateNumeric(string $attribute, mixed $value)
Validate that an attribute is numeric.
protected bool validatePassword(string $attribute, mixed $value, array $parameters)
Validate that the current logged in user's password matches the given value.
bool validatePresent(string $attribute, mixed $value)
Validate that an attribute exists even if not filled.
bool validateRegex(string $attribute, mixed $value, array $parameters)
Validate that an attribute passes a regular expression check.
bool validateNotRegex(string $attribute, mixed $value, array $parameters)
Validate that an attribute does not pass a regular expression check.
bool validateRequired(string $attribute, mixed $value)
Validate that a required attribute exists.
bool validateRequiredIf(string $attribute, mixed $value, mixed $parameters)
Validate that an attribute exists when another attribute has a given value.
bool validateExcludeIf(string $attribute, mixed $value, mixed $parameters)
Indicate that an attribute should be excluded when another attribute has a given value.
bool validateExcludeUnless(string $attribute, mixed $value, mixed $parameters)
Indicate that an attribute should be excluded when another attribute does not have a given value.
bool validateExcludeWithout(string $attribute, mixed $value, mixed $parameters)
Indicate that an attribute should be excluded when another attribute is missing.
protected array prepareValuesAndOther(array $parameters)
Prepare the values and the other value for validation.
protected array convertValuesToBoolean(array $values)
Convert the given values to boolean if they are string "true" / "false".
bool validateRequiredUnless(string $attribute, mixed $value, mixed $parameters)
Validate that an attribute exists when another attribute does not have a given value.
bool validateRequiredWith(string $attribute, mixed $value, mixed $parameters)
Validate that an attribute exists when any other attribute exists.
bool validateRequiredWithAll(string $attribute, mixed $value, mixed $parameters)
Validate that an attribute exists when all other attributes exists.
bool validateRequiredWithout(string $attribute, mixed $value, mixed $parameters)
Validate that an attribute exists when another attribute does not.
bool validateRequiredWithoutAll(string $attribute, mixed $value, mixed $parameters)
Validate that an attribute exists when all other attributes do not.
protected bool anyFailingRequired(array $attributes)
Determine if any of the given attributes fail the required test.
protected bool allFailingRequired(array $attributes)
Determine if all of the given attributes fail the required test.
bool validateSame(string $attribute, mixed $value, array $parameters)
Validate that two attributes match.
bool validateSize(string $attribute, mixed $value, array $parameters)
Validate the size of an attribute.
bool validateSometimes()
"Validate" optional attributes.
Always returns true, just lets us put sometimes in rules.
bool validateStartsWith(string $attribute, mixed $value, array $parameters)
Validate the attribute starts with a given substring.
bool validateEndsWith(string $attribute, mixed $value, array $parameters)
Validate the attribute ends with a given substring.
bool validateString(string $attribute, mixed $value)
Validate that an attribute is a string.
bool validateTimezone(string $attribute, mixed $value)
Validate that an attribute is a valid timezone.
bool validateUrl(string $attribute, mixed $value)
Validate that an attribute is a valid URL.
bool validateUuid(string $attribute, mixed $value)
Validate that an attribute is a valid UUID.
protected mixed getSize(string $attribute, mixed $value)
Get the size of an attribute.
bool isValidFileInstance(mixed $value)
Check that the given value is a valid file instance.
protected bool compare(mixed $first, mixed $second, string $operator)
Determine if a comparison passes between the given values.
protected array parseNamedParameters(array $parameters)
Parse named parameters to $key => $value items.
void requireParameterCount(int $count, array $parameters, string $rule)
Require a certain number of parameters to be present.
protected bool isSameType(mixed $first, mixed $second)
Check if the parameters are of the same type.
protected void shouldBeNumeric(string $attribute, string $rule)
Adds the existing rule to the numericRules array if the attribute's value is numeric.
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/7.x/Illuminate/Validation/Concerns/ValidatesAttributes.html