W3cubDocs

/Laravel 5.1

Validator

class Validator implements Validator (View source)

Methods

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

Create a new Validator instance.

$this after( callable|string $callback)

After an after validation callback.

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

Add conditions to a given field based on a Closure.

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

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

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

Merge additional rules into a given attribute.

bool passes()

Determine if the data passes the validation rules.

bool fails()

Determine if the data fails the validation rules.

array valid()

Returns the data which was valid.

array invalid()

Returns the data which was invalid.

string getDisplayableValue( string $attribute, mixed $value)

Get the displayable name of the value.

array getExtensions()

Get the array of custom validator extensions.

void addExtensions( array $extensions)

Register an array of custom validator extensions.

void addImplicitExtensions( array $extensions)

Register an array of custom implicit validator extensions.

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

Register a custom validator extension.

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

Register a custom implicit validator extension.

array getReplacers()

Get the array of custom validator message replacers.

void addReplacers( array $replacers)

Register an array of custom validator message replacers.

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

Register a custom validator message replacer.

array getData()

Get the data under validation.

void setData( array $data)

Set the data under validation.

array getRules()

Get the validation rules.

$this setRules( array $rules)

Set the validation rules.

$this setAttributeNames( array $attributes)

Set the custom attributes on the validator.

$this setValueNames( array $values)

Set the custom values on the validator.

array getFiles()

Get the files under validation.

$this setFiles( array $files)

Set the files under validation.

PresenceVerifierInterface getPresenceVerifier()

Get the Presence Verifier implementation.

void setPresenceVerifier( PresenceVerifierInterface $presenceVerifier)

Set the Presence Verifier implementation.

TranslatorInterface getTranslator()

Get the Translator implementation.

void setTranslator( TranslatorInterface $translator)

Set the Translator implementation.

array getCustomMessages()

Get the custom messages for the validator.

void setCustomMessages( array $messages)

Set the custom messages for the validator.

array getCustomAttributes()

Get the custom attributes used by the validator.

$this addCustomAttributes( array $customAttributes)

Add custom attributes to the validator.

array getCustomValues()

Get the custom values for the validator.

$this addCustomValues( array $customValues)

Add the custom values for the validator.

array getFallbackMessages()

Get the fallback messages for the validator.

void setFallbackMessages( array $messages)

Set the fallback messages for the validator.

array failed()

Get the failed validation rules.

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.

void setContainer( Container $container)

Set the IoC container instance.

mixed __call( string $method, array $parameters)

Handle dynamic calls to class methods.

Details

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

Create a new Validator instance.

Parameters

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

Return Value

void

$this after( callable|string $callback)

After an after validation callback.

Parameters

callable|string $callback

Return Value

$this

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

Add conditions to a given field based on a Closure.

Parameters

string $attribute
string|array $rules
callable $callback

Return Value

void

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

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

Parameters

string $attribute
string|array $rules

Return Value

void

Exceptions

InvalidArgumentException

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

Merge additional rules into a given attribute.

Parameters

string $attribute
string|array $rules

Return Value

void

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

array valid()

Returns the data which was valid.

Return Value

array

array invalid()

Returns the data which was invalid.

Return Value

array

string getDisplayableValue( string $attribute, mixed $value)

Get the displayable name of the value.

Parameters

string $attribute
mixed $value

Return Value

string

array getExtensions()

Get the array of custom validator extensions.

Return Value

array

void addExtensions( array $extensions)

Register an array of custom validator extensions.

Parameters

array $extensions

Return Value

void

void addImplicitExtensions( array $extensions)

Register an array of custom implicit validator extensions.

Parameters

array $extensions

Return Value

void

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

Register a custom validator extension.

Parameters

string $rule
Closure|string $extension

Return Value

void

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

Register a custom implicit validator extension.

Parameters

string $rule
Closure|string $extension

Return Value

void

array getReplacers()

Get the array of custom validator message replacers.

Return Value

array

void addReplacers( array $replacers)

Register an array of custom validator message replacers.

Parameters

array $replacers

Return Value

void

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

Register a custom validator message replacer.

Parameters

string $rule
Closure|string $replacer

Return Value

void

array getData()

Get the data under validation.

Return Value

array

void setData( array $data)

Set the data under validation.

Parameters

array $data

Return Value

void

array getRules()

Get the validation rules.

Return Value

array

$this setRules( array $rules)

Set the validation rules.

Parameters

array $rules

Return Value

$this

$this setAttributeNames( array $attributes)

Set the custom attributes on the validator.

Parameters

array $attributes

Return Value

$this

$this setValueNames( array $values)

Set the custom values on the validator.

Parameters

array $values

Return Value

$this

array getFiles()

Get the files under validation.

Return Value

array

$this setFiles( array $files)

Set the files under validation.

Parameters

array $files

Return Value

$this

PresenceVerifierInterface getPresenceVerifier()

Get the Presence Verifier implementation.

void setPresenceVerifier( PresenceVerifierInterface $presenceVerifier)

Set the Presence Verifier implementation.

Parameters

PresenceVerifierInterface $presenceVerifier

Return Value

void

TranslatorInterface getTranslator()

Get the Translator implementation.

Return Value

TranslatorInterface

void setTranslator( TranslatorInterface $translator)

Set the Translator implementation.

Parameters

TranslatorInterface $translator

Return Value

void

array getCustomMessages()

Get the custom messages for the validator.

Return Value

array

void setCustomMessages( array $messages)

Set the custom messages for the validator.

Parameters

array $messages

Return Value

void

array getCustomAttributes()

Get the custom attributes used by the validator.

Return Value

array

$this addCustomAttributes( array $customAttributes)

Add custom attributes to the validator.

Parameters

array $customAttributes

Return Value

$this

array getCustomValues()

Get the custom values for the validator.

Return Value

array

$this addCustomValues( array $customValues)

Add the custom values for the validator.

Parameters

array $customValues

Return Value

$this

array getFallbackMessages()

Get the fallback messages for the validator.

Return Value

array

void setFallbackMessages( array $messages)

Set the fallback messages for the validator.

Parameters

array $messages

Return Value

void

array failed()

Get the failed validation rules.

Return Value

array

MessageBag messages()

Get the message container for the validator.

Return Value

MessageBag

MessageBag errors()

An alternative more semantic shortcut to the message container.

Return Value

MessageBag

MessageBag getMessageBag()

Get the messages for the instance.

Return Value

MessageBag

void setContainer( Container $container)

Set the IoC container instance.

Parameters

Container $container

Return Value

void

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/5.1/Illuminate/Validation/Validator.html