ValidationResult
final class ValidationResult (View source)
Simple validation result class following the Result pattern
Methods
Create a successful validation result
Create a failed validation result
Create a failed validation result with multiple errors
Check if validation succeeded
Get all validation error messages
Get first error message or empty string if no errors
Get data from successful validation
Check if the validation result has warnings
Get warnings from the validation result
Get first warning message or empty string if no warnings
Add a warning to the validation result
Add multiple warnings to the validation result
Details
static ValidationResult
success(mixed $data, array $warnings = [])
Create a successful validation result
static ValidationResult
failure(string|array $errors, array $warnings = [])
Create a failed validation result
static ValidationResult
errors(array $errors, array $warnings = [])
Create a failed validation result with multiple errors
bool
isValid()
Check if validation succeeded
array
getErrors()
Get all validation error messages
string
getFirstError()
Get first error message or empty string if no errors
getData()
Get data from successful validation
bool
hasWarnings()
Check if the validation result has warnings
array
getWarnings()
Get warnings from the validation result
string
getFirstWarning()
Get first warning message or empty string if no warnings
ValidationResult
addWarning(string $warning)
Add a warning to the validation result
ValidationResult
addWarnings(array $warnings)
Add multiple warnings to the validation result