Protected properties

protected Illuminate\Support\MessageBag $validationErrors

validationErrors message bag instance containing validation error messages

protected array $validationDefaultAttrNames

validationDefaultAttrNames default custom attribute names

Public methods

public static void bootValidation()

bootValidation for this model

public Illuminate\Support\MessageBag errors()

errors gets validation error message collection for the Model

public bool forceSave($options=NULL, $sessionKey=NULL)

forceSave the model even if validation fails

  • $options
  • $sessionKey

public boolean isAttributeRequired(string $attribute, boolean $checkDependencies=true)

isAttributeRequired determines if an attribute is required based on the validation rules. checkDependencies checks the attribute dependencies (for required_if & required_with rules). Note that it will only be checked up to the next level, if another dependent rule is found then it will just assume the field is required.

  • string $attribute
  • boolean $checkDependencies

public void setValidationAttributeName(string $attr, string $name)

setValidationAttributeName programatically sets the validation attribute names, will take lower priority to model defined attribute names found in $attributeNames

  • string $attr
  • string $name

public void setValidationAttributeNames(array $attributeNames)

setValidationAttributeNames programatically sets multiple validation attribute names

  • array $attributeNames

public bool validate($rules=NULL, $customMessages=NULL, $attributeNames=NULL)

validate the model instance

  • $rules
  • $customMessages
  • $attributeNames

public static void validated(Closure|string $callback)

validated create a new native event for handling afterValidate()

  • Closure|string $callback

public static void validating(Closure|string $callback)

validating creates a new native event for handling beforeValidate()

  • Closure|string $callback

Protected methods

protected void getRelationValidationValue($relationName)

getRelationValidationValue handles attachments that validate differently to their simple values

  • $relationName

protected array getValidationAttributes()

getValidationAttributes returns the model data used for validation

protected static Illuminate\Validation\Validator makeValidator($data, $rules, $customMessages, $attributeNames, $connection=NULL)

makeValidator instantiates the validator used by the validation process, depending if the class is being used inside or outside of Laravel. Optional connection string to make the validator use a different database connection than the default connection.

  • $data
  • $rules
  • $customMessages
  • $attributeNames
  • $connection

protected array processRuleFieldNames(array $rules)

processRuleFieldNames processes field names in a rule array

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

  • array $rules - Rules array

protected void processValidationRules($rules)


  • $rules

protected string processValidationUniqueRule(string $definition, string $fieldName)

processValidationUniqueRule rebuilds the unique validation rule to force for the existing ID

  • string $definition
  • string $fieldName