Skip to content

Commit da48acf

Browse files
committed
Update error message docs in README
1 parent aea98df commit da48acf

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

README.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,25 +209,40 @@ And `slug[nl]` would fail, because there already is a `nl` value of `abc`.
209209

210210
## ⚠️ Error Messages
211211

212-
Whether you are validating a single translation (`'slug'`) or an array of translations (`'slug.*'`), if validation fails, you will find an error for both the single and the localized key:
212+
You can pass your own error messages as normal.
213+
214+
When validating a single form field:
215+
216+
```html
217+
<input name="slug">
218+
```
213219

214220
```php
215-
$errors->first('slug');
216-
$errors->first('slug.en');
221+
$attributes = request()->validate([
222+
'slug' => 'unique_translation:posts',
223+
], [
224+
'slug.unique_translation' => 'Your custom :attribute error.',
225+
]);
217226
```
218227

219-
You can pass your own error message with any of the following keys. The first one found will be used.
228+
In your view you can then get the error with `$errors->first('slug')`.
229+
230+
Or when validation an array:
231+
232+
```html
233+
<input name="slug[en]">
234+
```
220235

221236
```php
222237
$attributes = request()->validate([
223238
'slug.*' => 'unique_translation:posts',
224239
], [
225-
'slug.unique_translation' => 'Your custom :attribute error.',
226240
'slug.*.unique_translation' => 'Your custom :attribute error.',
227-
'slug.en.unique_translation' => 'Your custom :attribute error.',
228241
]);
229242
```
230243

244+
In your view you can then get the error with `$errors->first('slug.en')` (`en` being your array key).
245+
231246
## 🚧 Testing
232247

233248
```

0 commit comments

Comments
 (0)