class Validator implements Validator (View source)

Traits

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.

string
getDisplayableAttribute(string $attribute)

Get the displayable name of the attribute.

string
getDisplayableValue(string $attribute, mixed $value)

Get the displayable name of the value.

string
guessColumnForQuery(string $attribute)

Guess the database column from the given attribute name.

bool
isValidFileInstance(mixed $value)

Check that the given value is a valid file instance.

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.

messages()

Get the message container for the validator.

errors()

An alternative more semantic shortcut to the message container.

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
addDependentExtensions(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
addDependentExtension(string $rule, Closure|string $extension)

Register a custom dependent 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.

getPresenceVerifier()

Get the Presence Verifier implementation.

void
setPresenceVerifier(PresenceVerifierInterface $presenceVerifier)

Set the Presence Verifier implementation.

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 getDisplayableAttribute(string $attribute)

Get the displayable name of the attribute.

Parameters

string $attribute

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

at line line 182
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

at line line 200
array parseData(array $data)

Parse the data array, converting dots to ->.

Parameters

array $data

Return Value

array

at line line 228
$this after(callable|string $callback)

Add an after validation callback.

Parameters

callable|string $callback

Return Value

$this

at line line 242
bool passes()

Determine if the data passes the validation rules.

Return Value

bool

at line line 276
bool fails()

Determine if the data fails the validation rules.

Return Value

bool

at line line 288
void validate()

Run the validator's rules against its data.

Return Value

void

Exceptions

ValidationException

at line line 547
array valid()

Returns the data which was valid.

Return Value

array

at line line 563
array invalid()

Returns the data which was invalid.

Return Value

array

at line line 591
array failed()

Get the failed validation rules.

Return Value

array

at line line 601
MessageBag messages()

Get the message container for the validator.

Return Value

MessageBag

at line line 615
MessageBag errors()

An alternative more semantic shortcut to the message container.

Return Value

MessageBag

at line line 625
MessageBag getMessageBag()

Get the messages for the instance.

Return Value

MessageBag

at line line 637
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

at line line 671
array attributes()

Get the data under validation.

Return Value

array

at line line 681
array getData()

Get the data under validation.

Return Value

array

at line line 692
$this setData(array $data)

Set the data under validation.

Parameters

array $data

Return Value

$this

at line line 717
array getRules()

Get the validation rules.

Return Value

array

at line line 728
$this setRules(array $rules)

Set the validation rules.

Parameters

array $rules

Return Value

$this

at line line 745
void addRules(array $rules)

Parse the given rules and merge them into current rules.

Parameters

array $rules

Return Value

void

at line line 770
$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

at line line 789
void addExtensions(array $extensions)

Register an array of custom validator extensions.

Parameters

array $extensions

Return Value

void

at line line 806
void addImplicitExtensions(array $extensions)

Register an array of custom implicit validator extensions.

Parameters

array $extensions

Return Value

void

at line line 821
void addDependentExtensions(array $extensions)

Register an array of custom implicit validator extensions.

Parameters

array $extensions

Return Value

void

at line line 837
void addExtension(string $rule, Closure|string $extension)

Register a custom validator extension.

Parameters

string $rule
Closure|string $extension

Return Value

void

at line line 849
void addImplicitExtension(string $rule, Closure|string $extension)

Register a custom implicit validator extension.

Parameters

string $rule
Closure|string $extension

Return Value

void

at line line 863
void addDependentExtension(string $rule, Closure|string $extension)

Register a custom dependent validator extension.

Parameters

string $rule
Closure|string $extension

Return Value

void

at line line 876
void addReplacers(array $replacers)

Register an array of custom validator message replacers.

Parameters

array $replacers

Return Value

void

at line line 894
void addReplacer(string $rule, Closure|string $replacer)

Register a custom validator message replacer.

Parameters

string $rule
Closure|string $replacer

Return Value

void

at line line 905
void setCustomMessages(array $messages)

Set the custom messages for the validator.

Parameters

array $messages

Return Value

void

at line line 916
$this setAttributeNames(array $attributes)

Set the custom attributes on the validator.

Parameters

array $attributes

Return Value

$this

at line line 929
$this addCustomAttributes(array $customAttributes)

Add custom attributes to the validator.

Parameters

array $customAttributes

Return Value

$this

at line line 942
$this setValueNames(array $values)

Set the custom values on the validator.

Parameters

array $values

Return Value

$this

at line line 955
$this addCustomValues(array $customValues)

Add the custom values for the validator.

Parameters

array $customValues

Return Value

$this

at line line 968
void setFallbackMessages(array $messages)

Set the fallback messages for the validator.

Parameters

array $messages

Return Value

void

at line line 980
PresenceVerifierInterface getPresenceVerifier()

Get the Presence Verifier implementation.

at line line 1010
void setPresenceVerifier(PresenceVerifierInterface $presenceVerifier)

Set the Presence Verifier implementation.

Parameters

PresenceVerifierInterface $presenceVerifier

Return Value

void

at line line 1020
Translator getTranslator()

Get the Translator implementation.

Return Value

Translator

at line line 1031
void setTranslator(Translator $translator)

Set the Translator implementation.

Parameters

Translator $translator

Return Value

void

at line line 1042
void setContainer(Container $container)

Set the IoC container instance.

Parameters

Container $container

Return Value

void

at line line 1088
mixed __call(string $method, array $parameters)

Handle dynamic calls to class methods.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException