W3cubDocs

/Laravel 5.4

Validator

class Validator implements Validator (View source)

Traits

FormatsMessages
ValidatesAttributes
ReplacesAttributes

Properties

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.

Methods

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

Replace all error message place-holders with actual values.

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

Get the displayable name of the value.

from FormatsMessages
string guessColumnForQuery(string $attribute)

Guess the database column from the given attribute name.

from ValidatesAttributes
bool isValidFileInstance(mixed $value)

Check that the given value is a valid file instance.

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

Create a new Validator instance.

array parseData(array $data)

Parse the data array, converting dots to ->.

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

void validate()

Run the validator's rules against its data.

array valid()

Returns the data which was valid.

array invalid()

Returns the data which was invalid.

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 attributes()

Get the data under validation.

array getData()

Get the data under validation.

$this setData(array $data)

Set the data under validation.

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 $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 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 addReplacers(array $replacers)

Register an array of custom validator message replacers.

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

Register a custom validator message replacer.

void 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 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()

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.

mixed __call(string $method, array $parameters)

Handle dynamic calls to class methods.

Details

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

Get the displayable name of the value.

Parameters

string $attribute
mixed $value

Return Value

string

string guessColumnForQuery(string $attribute)

Guess the database column from the given attribute name.

Parameters

string $attribute

Return Value

string

bool isValidFileInstance(mixed $value)

Check that the given value is a valid file instance.

Parameters

mixed $value

Return Value

bool

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

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

Parameters

array $data

Return Value

array

$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

void validate()

Run the validator's rules against its data.

Return Value

void

Exceptions

ValidationException

array valid()

Returns the data which was valid.

Return Value

array

array invalid()

Returns the data which was invalid.

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

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

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

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

void setCustomMessages(array $messages)

Set the custom messages for the validator.

Parameters

array $messages

Return Value

void

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

Get the Presence Verifier implementation.

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

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