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
You may also specify the field name of the validation failure to get a localized message for that field.
@@ -145,3 +145,17 @@ validation_error:
145
145
.input {$field :string}
146
146
{$field} must be a valid email address.
147
147
```
148
+
149
+
Sometimes though, you may want to have a specific error message for a rule, without overriding the default translation message for that rule.
150
+
151
+
This can be done by using the {b`#[Tempest\Validation\TranslationKey]`} attribute on the property being validated. For instance, you may have the following object:
152
+
153
+
```php
154
+
final class Book {
155
+
#[Rules\HasLength(min: 5, max: 50)]
156
+
#[TranslationKey('book_management.book_title')]
157
+
public string $title;
158
+
}
159
+
```
160
+
161
+
When this rule fails, the `getErrorMessage()` method from the validator will use `validation_error.has_length.book_management.book_title` as the translation key, instead of `validation_error.has_length`.
0 commit comments