Documentation

Validation

Table of Contents

$validationErrors  : MessageBag
$validator  : Validator
The validator instance.
bootValidation()  : void
Boot the validation trait for this model.
errors()  : MessageBag
Get validation error message collection for the Model
forceSave()  : bool
Force save the model even if validation fails.
getModelValidator()  : Validator
Get the validator instance.
isAttributeRequired()  : bool
Determines if an attribute is required based on the validation rules.
setModelValidator()  : void
Set the validator instance.
unsetModelValidator()  : void
Unset the validator for models.
validate()  : bool
Validate the model instance
validated()  : void
Create a new native event for handling afterValidate().
validating()  : void
Create a new native event for handling beforeValidate().
getValidationAttributes()  : array<string|int, mixed>
Returns the model data used for validation.
makeValidator()  : Validator
Instantiates the validator used by the validation process, depending if the class is being used inside or outside of Laravel.
processRuleFieldNames()  : array<string|int, mixed>
Processes field names in a rule array.
processValidationRules()  : mixed
Process rules

Properties

$validationErrors

protected MessageBag $validationErrors

The message bag instance containing validation error messages

Methods

bootValidation()

Boot the validation trait for this model.

public static bootValidation() : void
Return values
void

forceSave()

Force save the model even if validation fails.

public forceSave([mixed $options = null ]) : bool
Parameters
$options : mixed = null
Return values
bool

isAttributeRequired()

Determines if an attribute is required based on the validation rules.

public isAttributeRequired(string $attribute) : bool
Parameters
$attribute : string
Return values
bool

setModelValidator()

Set the validator instance.

public static setModelValidator(mixed $validator) : void
Parameters
$validator : mixed
Return values
void

unsetModelValidator()

Unset the validator for models.

public static unsetModelValidator() : void
Return values
void

validate()

Validate the model instance

public validate([mixed $rules = null ][, mixed $customMessages = null ][, mixed $attributeNames = null ]) : bool
Parameters
$rules : mixed = null
$customMessages : mixed = null
$attributeNames : mixed = null
Return values
bool

validated()

Create a new native event for handling afterValidate().

public static validated(Closure|string $callback) : void
Parameters
$callback : Closure|string
Return values
void

validating()

Create a new native event for handling beforeValidate().

public static validating(Closure|string $callback) : void
Parameters
$callback : Closure|string
Return values
void

getValidationAttributes()

Returns the model data used for validation.

protected getValidationAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed>

makeValidator()

Instantiates the validator used by the validation process, depending if the class is being used inside or outside of Laravel.

protected static makeValidator(mixed $data, mixed $rules, mixed $customMessages, mixed $attributeNames) : Validator
Parameters
$data : mixed
$rules : mixed
$customMessages : mixed
$attributeNames : mixed
Return values
Validator

processRuleFieldNames()

Processes field names in a rule array.

protected processRuleFieldNames(array<string|int, mixed> $rules) : array<string|int, mixed>

Converts any field names using array notation (ie. field[child]) into dot notation (ie. field.child)

Parameters
$rules : array<string|int, mixed>

Rules array

Return values
array<string|int, mixed>

processValidationRules()

Process rules

protected processValidationRules(mixed $rules) : mixed
Parameters
$rules : mixed
Return values
mixed

Search results