From ae7718338dff2a77629bef33bec329a593ab75c4 Mon Sep 17 00:00:00 2001 From: Francescu Garoby Date: Wed, 5 Nov 2025 11:30:25 +0100 Subject: [PATCH] feat: allow sub-array notation in arrays validation --- validation.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/validation.md b/validation.md index fef312d222..d18976e50c 100644 --- a/validation.md +++ b/validation.md @@ -2513,6 +2513,19 @@ $validator = Validator::make($request->all(), [ ]); ``` +You may also use the `*` as a key of a sub-array. For example, if your users have an `email` and a `last_name` in a given sub-array input field, you may do the following: + +```php +$validator = Validator::make($request->all(), [ + 'users' => [ + '*' => [ + 'email' => 'email|unique:users', + 'first_name' => 'required_with:users.*.last_name', + ], + ], +]); +``` + Likewise, you may use the `*` character when specifying [custom validation messages in your language files](#custom-messages-for-specific-attributes), making it a breeze to use a single validation message for array-based fields: ```php