class Illuminate / Validation / Validator

Validator

Implements

Uses

Properties

protected

$translator Translator

The Translator implementation.

Default: null
protected

$container Container

The container instance.

Default: null
protected

$presenceVerifier PresenceVerifierInterface

The Presence Verifier implementation.

Default: null
protected

$failedRules array

The failed validation rules.

Default: []
protected

$excludeAttributes array

Attributes that should be excluded from the validated data.

Default: []
protected

$messages MessageBag

The message bag instance.

Default: null
protected

$data array

The data under validation.

Default: null
protected

$initialRules array

The initial rules provided.

Default: null
protected

$rules array

The rules to be applied to the data.

Default: null
protected

$currentRule string

The current rule that is validating.

Default: null
protected

$implicitAttributes array

The array of wildcard attributes with their asterisks expanded.

Default: []
protected

$implicitAttributesFormatter callable|null

The callback that should be used to format the attribute.

Default: null
protected

$distinctValues array

The cached data for the "distinct" rule.

Default: []
protected

$after array

All of the registered "after" callbacks.

Default: []
public

$customMessages array

The array of custom error messages.

Default: []
public

$fallbackMessages array

The array of fallback error messages.

Default: []
public

$customAttributes array

The array of custom attribute names.

Default: []
public

$customValues array

The array of custom displayable values.

Default: []
protected

$stopOnFirstFailure bool

Indicates if the validator should stop on the first rule failure.

Default: false
public

$excludeUnvalidatedArrayKeys bool

Indicates that unvalidated array keys should be excluded, even if the parent array was validated.

Default: false
public

$extensions array

All of the custom validator extensions.

Default: []
public

$replacers array

All of the custom replacer extensions.

Default: []
protected

$fileRules string[]

The validation rules that may be applied to files.

Default: array
protected

$implicitRules string[]

The validation rules that imply the field is required.

Default: array
protected

$dependentRules string[]

The validation rules which depend on other fields as parameters.

Default: array
protected

$excludeRules string[]

The validation rules that can exclude an attribute.

Default: array
protected

$sizeRules string[]

The size related validation rules.

Default: array
protected

$numericRules string[]

The numeric related validation rules.

Default: array
protected

$dotPlaceholder string

The current placeholder for dots in rule keys.

Default: null
protected

$exception string

The exception to throw upon failure.

Default: class
protected

$ensureExponentWithinAllowedRangeUsing callable|null

The custom callback to determine if an exponent is within allowed range.

Default: null

Methods

public

__construct ( Translator $translator , array $data , array $rules , array $messages , array $attributes ) : void

Create a new Validator instance.

Parameters

  • $translator Translator
  • $data array
  • $rules array
  • $messages array
  • $attributes array
public

parseData ( array $data ) : array

Parse the data array, converting dots and asterisks.

Parameters

  • $data array
protected

replacePlaceholders ( $data ) : array

Replace the placeholders used in data keys.

Parameters

  • $data array
protected

replacePlaceholderInString ( string $value ) : string

Replace the placeholders in the given string.

Parameters

  • $value string
public

after ( $callback ) : $this

Add an after validation callback.

Parameters

  • $callback callable|array|string
public

passes ( ) : bool

Determine if the data passes the validation rules.

public

fails ( ) : bool

Determine if the data fails the validation rules.

protected

shouldBeExcluded ( $attribute ) : bool

Determine if the attribute should be excluded.

Parameters

  • $attribute string
protected

removeAttribute ( $attribute ) : void

Remove the given attribute.

Parameters

  • $attribute string
public

validate ( ) : array

Run the validator's rules against its data.

public

validateWithBag ( string $errorBag ) : array

Run the validator's rules against its data.

Parameters

  • $errorBag string
public

safe ( array $keys ) : ValidatedInput |array

Get a validated input container for the validated input.

Parameters

  • $keys array|null
public

validated ( ) : array

Get the attributes and values that were validated.

protected

validateAttribute ( $attribute , $rule ) : void

Validate a given attribute against a rule.

Parameters

  • $attribute string
  • $rule string
protected

dependsOnOtherFields ( $rule ) : bool

Determine if the given rule depends on other fields.

Parameters

  • $rule string
protected

getExplicitKeys ( $attribute ) : array

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

Parameters

  • $attribute string
protected

getPrimaryAttribute ( $attribute ) : string

Get the primary attribute name.

Parameters

  • $attribute string
protected

replaceDotInParameters ( array $parameters ) : array

Replace each field parameter which has an escaped dot with the dot placeholder.

Parameters

  • $parameters array
protected

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

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

Parameters

  • $parameters array
  • $keys array
protected

isValidatable ( $rule , $attribute , $value ) : bool

Determine if the attribute is validatable.

Parameters

  • $rule object|string
  • $attribute string
  • $value mixed
protected

presentOrRuleIsImplicit ( $rule , $attribute , $value ) : bool

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

Parameters

  • $rule object|string
  • $attribute string
  • $value mixed
protected

isImplicit ( $rule ) : bool

Determine if a given rule implies the attribute is required.

Parameters

  • $rule object|string
protected

passesOptionalCheck ( $attribute ) : bool

Determine if the attribute passes any optional check.

Parameters

  • $attribute string
protected

isNotNullIfMarkedAsNullable ( $rule , $attribute ) : bool

Determine if the attribute fails the nullable check.

Parameters

  • $rule string
  • $attribute string
protected

hasNotFailedPreviousRuleIfPresenceRule ( $rule , $attribute ) : bool

Determine if it's a necessary presence validation.

Parameters

  • $rule string
  • $attribute string
protected

validateUsingCustomRule ( $attribute , $value , $rule ) : void

Validate an attribute using a custom rule object.

Parameters

  • $attribute string
  • $value mixed
  • $rule Rule
protected

shouldStopValidating ( $attribute ) : bool

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

Parameters

  • $attribute string
public

addFailure ( $attribute , $rule , $parameters ) : void

Add a failed rule and error message to the collection.

Parameters

  • $attribute string
  • $rule string
  • $parameters array
protected

excludeAttribute ( string $attribute ) : void

Add the given attribute to the list of excluded attributes.

Parameters

  • $attribute string
public

valid ( ) : array

Returns the data which was valid.

public

invalid ( ) : array

Returns the data which was invalid.

protected

attributesThatHaveMessages ( ) : array

Generate an array of all attributes that have messages.

public

failed ( ) : array

Get the failed validation rules.

public

messages ( ) : MessageBag

Get the message container for the validator.

public

errors ( ) : MessageBag

An alternative more semantic shortcut to the message container.

public

getMessageBag ( ) : MessageBag

Get the messages for the instance.

public

hasRule ( $attribute , $rules ) : bool

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

Parameters

  • $attribute string
  • $rules string|array
protected

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

Get a rule and its parameters for a given attribute.

Parameters

  • $attribute string
  • $rules string|array
public

attributes ( ) : array

Get the data under validation.

public

getData ( ) : array

Get the data under validation.

public

setData ( array $data ) : $this

Set the data under validation.

Parameters

  • $data array
protected

getValue ( $attribute ) : mixed

Get the value of a given attribute.

Parameters

  • $attribute string
public

setValue ( $attribute , $value ) : void

Set the value of a given attribute.

Parameters

  • $attribute string
  • $value mixed
public

getRules ( ) : array

Get the validation rules.

public

getRulesWithoutPlaceholders ( ) : array

Get the validation rules with key placeholders removed.

public

setRules ( array $rules ) : $this

Set the validation rules.

Parameters

  • $rules array
public

addRules ( $rules ) : void

Parse the given rules and merge them into current rules.

Parameters

  • $rules array
public

sometimes ( $attribute , $rules , callable $callback ) : $this

Add conditions to a given field based on a Closure.

Parameters

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

dataForSometimesIteration ( string $attribute , $removeLastSegmentOfAttribute ) : Illuminate\...\Fluent|array|mixed

Get the data that should be injected into the iteration of a wildcard "sometimes" callback.

Parameters

  • $attribute string
public

stopOnFirstFailure ( $stopOnFirstFailure ) : $this

Instruct the validator to stop validating after the first rule failure.

Parameters

  • $stopOnFirstFailure bool
public

addExtensions ( array $extensions ) : void

Register an array of custom validator extensions.

Parameters

  • $extensions array
public

addImplicitExtensions ( array $extensions ) : void

Register an array of custom implicit validator extensions.

Parameters

  • $extensions array
public

addDependentExtensions ( array $extensions ) : void

Register an array of custom dependent validator extensions.

Parameters

  • $extensions array
public

addExtension ( $rule , $extension ) : void

Register a custom validator extension.

Parameters

  • $rule string
  • $extension Closure |string
public

addImplicitExtension ( $rule , $extension ) : void

Register a custom implicit validator extension.

Parameters

  • $rule string
  • $extension Closure |string
public

addDependentExtension ( $rule , $extension ) : void

Register a custom dependent validator extension.

Parameters

  • $rule string
  • $extension Closure |string
public

addReplacers ( array $replacers ) : void

Register an array of custom validator message replacers.

Parameters

  • $replacers array
public

addReplacer ( $rule , $replacer ) : void

Register a custom validator message replacer.

Parameters

  • $rule string
  • $replacer Closure |string
public

setCustomMessages ( array $messages ) : $this

Set the custom messages for the validator.

Parameters

  • $messages array
public

setAttributeNames ( array $attributes ) : $this

Set the custom attributes on the validator.

Parameters

  • $attributes array
public

addCustomAttributes ( array $attributes ) : $this

Add custom attributes to the validator.

Parameters

  • $attributes array
public

setImplicitAttributesFormatter ( callable $formatter ) : $this

Set the callback that used to format an implicit attribute.

Parameters

  • $formatter callable|null
public

setValueNames ( array $values ) : $this

Set the custom values on the validator.

Parameters

  • $values array
public

addCustomValues ( array $customValues ) : $this

Add the custom values for the validator.

Parameters

  • $customValues array
public

setFallbackMessages ( array $messages ) : void

Set the fallback messages for the validator.

Parameters

  • $messages array
public

getPresenceVerifier ( $connection ) : PresenceVerifierInterface

Get the Presence Verifier implementation.

Parameters

  • $connection string|null
public

setPresenceVerifier ( PresenceVerifierInterface $presenceVerifier ) : void

Set the Presence Verifier implementation.

Parameters

public

setException ( $exception ) : $this

Set the exception to throw upon failed validation.

Parameters

  • $exception string
public

ensureExponentWithinAllowedRangeUsing ( $callback ) : $this

Ensure exponents are within range using the given callback.

Parameters

  • $callback callable
public

getTranslator ( ) : Translator

Get the Translator implementation.

public

setTranslator ( Translator $translator ) : void

Set the Translator implementation.

Parameters

public

setContainer ( Container $container ) : void

Set the IoC container instance.

Parameters

protected

callExtension ( $rule , $parameters ) : bool|null

Call a custom validator extension.

Parameters

  • $rule string
  • $parameters array
protected

callClassBasedExtension ( $callback , $parameters ) : bool

Call a class based validator extension.

Parameters

  • $callback string
  • $parameters array
public

__call ( $method , $parameters ) : mixed

Handle dynamic calls to class methods.

Parameters

  • $method string
  • $parameters array