Back to Error Center
422 Validation Error
Error Message
422 The given data was invalid.
Cause
The request data failed validation rules defined in Form Requests or inline validation. The response contains a JSON or session errors object.
Solution
Check the validation errors in the response. Review the rules in the Form Request. Ensure all required fields are present and valid.
Code Example
Fix
// Check validation errors
if ($errors = $request->session()->get('errors')) {
$errors->getMessages();
}
// In Blade
@error('title')
<span class="error">{{ $message }}</span>
@enderror
// In API response (automatic)
// {
// "message": "The given data was invalid.",
// "errors": {
// "title": ["The title field is required."]
// }
// }
Debugging Steps
- Check the validation errors in the response
- Review the Form Request rules() method
- Verify all required fields are included
- Check input data types match expected types
- Test with dd($request->all()) to inspect input
Prevention
Write comprehensive tests for validation rules. Use custom error messages for clarity. Always check required fields and data types.