trait Validation

Properties

protected MessageBag $validationErrors

Error messages as provided by the validator.

protected array $validationDefaultAttrNames
protected bool $validating

Whether the model should undergo validation when saving or not.

protected Factory $validator

The Validator factory class used for validation.

Methods

static void
bootValidation()

Boot the trait. Adds an observer class for validating.

bool
getValidating()

Returns whether or not the model will attempt to validate itself when saving.

void
setValidating(bool $value)

Set whether the model should attempt validation on saving.

array
getValidationAttributes()

Get the casted model attributes.

array
getValidationMessages()

Get the custom validation messages being used by the model.

array
getValidationAttributeNames()

Get the custom validation attribute names being used by the model.

Factory
getValidator()

Get the Validator instance.

validate()

No description

array
getRules()

Get the global validation rules.

MessageBag
getErrors()

Get the validation error messages from the model.

void
setErrors(MessageBag $validationErrors)

Set the error messages.

throwValidationException()

Throw a validation exception.

bool
getThrowValidationExceptions()

Returns whether the model will raise an exception or return a boolean when validating.

bool
getInjectUniqueIdentifier()

Returns whether or not the model will add it's unique identifier to the rules when validating.

void
setInjectUniqueIdentifier(bool $value)

Set the model to add unique identifier to rules when performing validation.

bool
performValidation(string $event)

Perform validation with the specified ruleset.

makeValidator($rules = [])

No description

mixed
fireValidatingEvents(string $event)

Fire the namespaced validating event.

void
fireValidatedEvents(string $status)

Fire the namespaced post-validation event.

array
injectUniqueIdentifierToRules(array $rules)

If the model already exists and it has unique validations it is going to fail validation unless we also pass it's primary key to the rule so that it may be ignored.

mixed
getUniqueIdentifierInjectorMethod(string $validationRule)

Get the dynamic method name for a unique identifier injector rule if it exists, otherwise return false.

string
processValidationUniqueRule(string $definition, string $fieldName)

Rebuilds the unique validation rule to force for the existing ID

Details

at line 50
static void bootValidation()

Boot the trait. Adds an observer class for validating.

Return Value

void

at line 76
bool getValidating()

Returns whether or not the model will attempt to validate itself when saving.

Return Value

bool

at line 87
void setValidating(bool $value)

Set whether the model should attempt validation on saving.

Parameters

bool $value

Return Value

void

at line 97
array getValidationAttributes()

Get the casted model attributes.

Return Value

array

at line 107
array getValidationMessages()

Get the custom validation messages being used by the model.

Return Value

array

at line 117
array getValidationAttributeNames()

Get the custom validation attribute names being used by the model.

Return Value

array

at line 127
Factory getValidator()

Get the Validator instance.

Return Value

Factory

at line 132
validate()

No description

at line 148
array getRules()

Get the global validation rules.

Return Value

array

at line 158
MessageBag getErrors()

Get the validation error messages from the model.

Return Value

MessageBag

at line 169
void setErrors(MessageBag $validationErrors)

Set the error messages.

Parameters

MessageBag $validationErrors

Return Value

void

at line 179
throwValidationException()

Throw a validation exception.

Exceptions

Validation

at line 192
bool getThrowValidationExceptions()

Returns whether the model will raise an exception or return a boolean when validating.

Return Value

bool

at line 203
bool getInjectUniqueIdentifier()

Returns whether or not the model will add it's unique identifier to the rules when validating.

Return Value

bool

at line 216
void setInjectUniqueIdentifier(bool $value)

Set the model to add unique identifier to rules when performing validation.

Parameters

bool $value

Return Value

void

Exceptions

InvalidArgumentException

at line 227
protected bool performValidation(string $event)

Perform validation with the specified ruleset.

Parameters

string $event

Return Value

bool

at line 258
protected makeValidator($rules = [])

No description

Parameters

$rules

at line 284
protected mixed fireValidatingEvents(string $event)

Fire the namespaced validating event.

Parameters

string $event

Return Value

mixed

at line 303
protected void fireValidatedEvents(string $status)

Fire the namespaced post-validation event.

Parameters

string $status

Return Value

void

at line 320
protected array injectUniqueIdentifierToRules(array $rules)

If the model already exists and it has unique validations it is going to fail validation unless we also pass it's primary key to the rule so that it may be ignored.

This will go through all the rules and append the model's primary key to the unique rules so that the validation will work as expected.

Parameters

array $rules

Return Value

array

at line 361
protected mixed getUniqueIdentifierInjectorMethod(string $validationRule)

Get the dynamic method name for a unique identifier injector rule if it exists, otherwise return false.

Parameters

string $validationRule

Return Value

mixed

at line 374
protected string processValidationUniqueRule(string $definition, string $fieldName)

Rebuilds the unique validation rule to force for the existing ID

Parameters

string $definition
string $fieldName

Return Value

string