You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/2-features/03-validation.md
+23Lines changed: 23 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -138,6 +138,29 @@ $this->validator->validateValue('jon@doe.co', function (mixed $value) {
138
138
});
139
139
```
140
140
141
+
## Throwing validation failures manually
142
+
143
+
You may throw a {`Tempest\Validation\Exceptions\ValidationFailed`} exception with custom messages when validation depends on application logic instead of a validation rule.
144
+
145
+
```php app/PasskeyController.php
146
+
use Tempest\Validation\Exceptions\ValidationFailed;
147
+
148
+
throw ValidationFailed::withMessages([
149
+
'credential' => 'Passkey not valid',
150
+
]);
151
+
```
152
+
153
+
Multiple messages may be passed for the same field.
154
+
155
+
```php
156
+
throw ValidationFailed::withMessages([
157
+
'email' => [
158
+
'Email is already taken',
159
+
'Email domain is not allowed',
160
+
],
161
+
]);
162
+
```
163
+
141
164
## Accessing error messages
142
165
143
166
When validation fails, a list of fields and their respective failing rules is returned. You may call the `getErrorMessage` method on the validator to get a [localized](./11-localization.md) validation message.
0 commit comments