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 196
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 214
array parseData(array $data)

Parse the data array, converting dots to ->.

Parameters

array $data

Return Value

array

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

Add an after validation callback.

Parameters

callable|string $callback

Return Value

$this

at line line 256
bool passes()

Determine if the data passes the validation rules.

Return Value

bool

at line line 290
bool fails()

Determine if the data fails the validation rules.

Return Value

bool

at line line 302
void validate()

Run the validator's rules against its data.

Return Value

void

Exceptions

ValidationException

at line line 561
array valid()

Returns the data which was valid.

Return Value

array

at line line 577
array invalid()

Returns the data which was invalid.

Return Value

array

at line line 605
array failed()

Get the failed validation rules.

Return Value

array

at line line 615
MessageBag messages()

Get the message container for the validator.

Return Value

MessageBag

at line line 629
MessageBag errors()

An alternative more semantic shortcut to the message container.

Return Value

MessageBag

at line line 639
MessageBag getMessageBag()

Get the messages for the instance.

Return Value

MessageBag

at line line 651
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 685
array attributes()

Get the data under validation.

Return Value

array

at line line 695
array getData()

Get the data under validation.

Return Value

array

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

Set the data under validation.

Parameters

array $data

Return Value

$this

at line line 731
array getRules()

Get the validation rules.

Return Value

array

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

Set the validation rules.

Parameters

array $rules

Return Value

$this

at line line 759
void addRules(array $rules)

Parse the given rules and merge them into current rules.

Parameters

array $rules

Return Value

void

at line line 784
$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 803
void addExtensions(array $extensions)

Register an array of custom validator extensions.

Parameters

array $extensions

Return Value

void

at line line 820
void addImplicitExtensions(array $extensions)

Register an array of custom implicit validator extensions.

Parameters

array $extensions

Return Value

void

at line line 835
void addDependentExtensions(array $extensions)

Register an array of custom implicit validator extensions.

Parameters

array $extensions

Return Value

void

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

Register a custom validator extension.

Parameters

string $rule
Closure|string $extension

Return Value

void

at line line 863
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 877
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 890
void addReplacers(array $replacers)

Register an array of custom validator message replacers.

Parameters

array $replacers

Return Value

void

at line line 908
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 919
void setCustomMessages(array $messages)

Set the custom messages for the validator.

Parameters

array $messages

Return Value

void

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

Set the custom attributes on the validator.

Parameters

array $attributes

Return Value

$this

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

Add custom attributes to the validator.

Parameters

array $customAttributes

Return Value

$this

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

Set the custom values on the validator.

Parameters

array $values

Return Value

$this

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

Add the custom values for the validator.

Parameters

array $customValues

Return Value

$this

at line line 982
void setFallbackMessages(array $messages)

Set the fallback messages for the validator.

Parameters

array $messages

Return Value

void

at line line 994
PresenceVerifierInterface getPresenceVerifier()

Get the Presence Verifier implementation.

at line line 1024
void setPresenceVerifier(PresenceVerifierInterface $presenceVerifier)

Set the Presence Verifier implementation.

Parameters

PresenceVerifierInterface $presenceVerifier

Return Value

void

at line line 1034
Translator getTranslator()

Get the Translator implementation.

Return Value

Translator

at line line 1045
void setTranslator(Translator $translator)

Set the Translator implementation.

Parameters

Translator $translator

Return Value

void

at line line 1056
void setContainer(Container $container)

Set the IoC container instance.

Parameters

Container $container

Return Value

void

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

Handle dynamic calls to class methods.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException