Skip to content

Model Object

hasErrors()

hasErrors() — returns boolean

Available in: model Category: Error Functions

Returns true if the object has any errors. You can also limit to only check a specific property or name for errors.

NameTypeRequiredDefaultDescription
propertystringno—Name of the property to check if there are any errors set on.
namestringno—Error name to check if there are any errors set with.
// 1. Check if a post object has any errors at all
if (post.hasErrors()) {
    // Redirect user back to the form to correct errors
}

// 2. Check if a specific property has errors
if (post.hasErrors(property="title")) {
    // The title field has at least one error
}

// 3. Check if any errors were set with a specific name
if (post.hasErrors(name="uniquenessViolation")) {
    // Handle uniqueness error specifically
}