From cb4656ed68bf0007b2b8940d448e3ee563e3e8eb Mon Sep 17 00:00:00 2001 From: ghabriel Date: Thu, 20 Nov 2025 11:03:06 +0700 Subject: [PATCH 1/4] feat: [12.x] Adds missing documentation for encoding rule --- validation.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/validation.md b/validation.md index fef312d222..f04ba2ddc6 100644 --- a/validation.md +++ b/validation.md @@ -1075,6 +1075,7 @@ Below is a list of all available validation rules and their function: [Between](#rule-between) [Dimensions](#rule-dimensions) +[Encoding](#rule-encoding) [Extensions](#rule-extensions) [File](#rule-file) [Image](#rule-image) @@ -1503,6 +1504,25 @@ Validator::make($data, [ ]); ``` + +#### encoding:*encoding_type* + +The field under validation must match the specified character encoding. This rule uses PHP's `mb_check_encoding()` function to verify the encoding of both strings and file contents. + +For convenience, encoding rule may be constructed using the fluent file rule builder: + +```php +use Illuminate\Support\Facades\Validator; +use Illuminate\Validation\Rules\File; + +Validator::validate($input, [ + 'attachment' => [ + 'required', + File::rule()->encoding('utf-8'), + ], +]); +``` + #### distinct From 4477d1f5a23de3be6f5077a5fa3851c06fa8a662 Mon Sep 17 00:00:00 2001 From: ghabriel Date: Thu, 20 Nov 2025 11:15:58 +0700 Subject: [PATCH 2/4] fix the placement --- validation.md | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/validation.md b/validation.md index f04ba2ddc6..32bcc4dbb6 100644 --- a/validation.md +++ b/validation.md @@ -1504,25 +1504,6 @@ Validator::make($data, [ ]); ``` - -#### encoding:*encoding_type* - -The field under validation must match the specified character encoding. This rule uses PHP's `mb_check_encoding()` function to verify the encoding of both strings and file contents. - -For convenience, encoding rule may be constructed using the fluent file rule builder: - -```php -use Illuminate\Support\Facades\Validator; -use Illuminate\Validation\Rules\File; - -Validator::validate($input, [ - 'attachment' => [ - 'required', - File::rule()->encoding('utf-8'), - ], -]); -``` - #### distinct @@ -1595,6 +1576,25 @@ $request->validate([ > [!WARNING] > The `dns` and `spoof` validators require the PHP `intl` extension. + +#### encoding:*encoding_type* + +The field under validation must match the specified character encoding. This rule uses PHP's `mb_check_encoding()` function to verify the encoding of both strings and file contents. + +For convenience, encoding rule may be constructed using the fluent file rule builder: + +```php +use Illuminate\Support\Facades\Validator; +use Illuminate\Validation\Rules\File; + +Validator::validate($input, [ + 'attachment' => [ + 'required', + File::rule()->encoding('utf-8'), + ], +]); +``` + #### ends_with:_foo_,_bar_,... From ce24d0df3e8237e2546b7a97349bb6fc31d624f7 Mon Sep 17 00:00:00 2001 From: Rihulfa Akbar <151924216+ghabriel25@users.noreply.github.com> Date: Thu, 20 Nov 2025 20:43:21 +0700 Subject: [PATCH 3/4] Update validation.md Co-authored-by: Jamie York --- validation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validation.md b/validation.md index 32bcc4dbb6..d6a3c1bbee 100644 --- a/validation.md +++ b/validation.md @@ -1590,7 +1590,7 @@ use Illuminate\Validation\Rules\File; Validator::validate($input, [ 'attachment' => [ 'required', - File::rule()->encoding('utf-8'), + File::encoding('utf-8'), ], ]); ``` From 65067babf089c5fb99209425ddfdc6c8aedc9b03 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 20 Nov 2025 10:49:02 -0600 Subject: [PATCH 4/4] Update validation.md --- validation.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/validation.md b/validation.md index d6a3c1bbee..c865646042 100644 --- a/validation.md +++ b/validation.md @@ -1579,9 +1579,7 @@ $request->validate([ #### encoding:*encoding_type* -The field under validation must match the specified character encoding. This rule uses PHP's `mb_check_encoding()` function to verify the encoding of both strings and file contents. - -For convenience, encoding rule may be constructed using the fluent file rule builder: +The field under validation must match the specified character encoding. This rule uses PHP's `mb_check_encoding` function to verify the encoding of the given file or string value. For convenience, the `encoding` rule may be constructed using Laravel's fluent file rule builder: ```php use Illuminate\Support\Facades\Validator; @@ -1590,7 +1588,8 @@ use Illuminate\Validation\Rules\File; Validator::validate($input, [ 'attachment' => [ 'required', - File::encoding('utf-8'), + File::types(['csv']) + ->encoding('utf-8'), ], ]); ```