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
@@ -1062,11 +1062,36 @@ Instead of passing a date string to be evaluated by `strtotime`, you may specify
1062
1062
1063
1063
'finish_date' => 'required|date|after:start_date'
1064
1064
1065
+
For convenience, date based rules may be constructed using the fluent `date` rule builder:
1066
+
1067
+
use Illuminate\Validation\Rule;
1068
+
1069
+
'start_date' => [
1070
+
'required',
1071
+
Rule::date()->after(today()->addDays(7)),
1072
+
],
1073
+
1074
+
The `afterToday` and `todayOrAfter` methods may be used to fluently express the date must be after today or or today or after, respectively:
1075
+
1076
+
'start_date' => [
1077
+
'required',
1078
+
Rule::date()->afterToday(),
1079
+
],
1080
+
1065
1081
<aname="rule-after-or-equal"></a>
1066
1082
#### after\_or\_equal:_date_
1067
1083
1068
1084
The field under validation must be a value after or equal to the given date. For more information, see the [after](#rule-after) rule.
1069
1085
1086
+
For convenience, date based rules may be constructed using the fluent `date` rule builder:
1087
+
1088
+
use Illuminate\Validation\Rule;
1089
+
1090
+
'start_date' => [
1091
+
'required',
1092
+
Rule::date()->afterOrEqual(today()->addDays(7)),
1093
+
],
1094
+
1070
1095
<aname="rule-alpha"></a>
1071
1096
#### alpha
1072
1097
@@ -1144,11 +1169,36 @@ While the `bail` rule will only stop validating a specific field when it encount
1144
1169
1145
1170
The field under validation must be a value preceding the given date. The dates will be passed into the PHP `strtotime` function in order to be converted into a valid `DateTime` instance. In addition, like the [`after`](#rule-after) rule, the name of another field under validation may be supplied as the value of `date`.
1146
1171
1172
+
For convenience, date based rules may also be constructed using the fluent `date` rule builder:
1173
+
1174
+
use Illuminate\Validation\Rule;
1175
+
1176
+
'start_date' => [
1177
+
'required',
1178
+
Rule::date()->before(today()->subDays(7)),
1179
+
],
1180
+
1181
+
The `beforeToday` and `todayOrBefore` methods may be used to fluently express the date must be before today or or today or before, respectively:
1182
+
1183
+
'start_date' => [
1184
+
'required',
1185
+
Rule::date()->beforeToday(),
1186
+
],
1187
+
1147
1188
<aname="rule-before-or-equal"></a>
1148
1189
#### before\_or\_equal:_date_
1149
1190
1150
1191
The field under validation must be a value preceding or equal to the given date. The dates will be passed into the PHP `strtotime` function in order to be converted into a valid `DateTime` instance. In addition, like the [`after`](#rule-after) rule, the name of another field under validation may be supplied as the value of `date`.
1151
1192
1193
+
For convenience, date based rules may also be constructed using the fluent `date` rule builder:
1194
+
1195
+
use Illuminate\Validation\Rule;
1196
+
1197
+
'start_date' => [
1198
+
'required',
1199
+
Rule::date()->beforeOrEqual(today()->subDays(7)),
1200
+
],
1201
+
1152
1202
<aname="rule-between"></a>
1153
1203
#### between:_min_,_max_
1154
1204
@@ -1193,6 +1243,15 @@ The field under validation must be equal to the given date. The dates will be pa
1193
1243
1194
1244
The field under validation must match one of the given _formats_. You should use **either**`date` or `date_format` when validating a field, not both. This validation rule supports all formats supported by PHP's [DateTime](https://www.php.net/manual/en/class.datetime.php) class.
1195
1245
1246
+
For convenience, date based rules may be constructed using the fluent `date` rule builder:
1247
+
1248
+
use Illuminate\Validation\Rule;
1249
+
1250
+
'start_date' => [
1251
+
'required',
1252
+
Rule::date()->format('Y-m-d'),
1253
+
],
1254
+
1196
1255
<aname="rule-decimal"></a>
1197
1256
#### decimal:_min_,_max_
1198
1257
@@ -1242,15 +1301,18 @@ A _ratio_ constraint should be represented as width divided by height. This can
1242
1301
1243
1302
'avatar' => 'dimensions:ratio=3/2'
1244
1303
1245
-
Since this rule requires several arguments, you may use the `Rule::dimensions` method to fluently construct the rule:
1304
+
Since this rule requires several arguments, it is often more convenient to use use the `Rule::dimensions` method to fluently construct the rule:
@@ -2196,42 +2258,60 @@ Laravel provides a variety of validation rules that may be used to validate uplo
2196
2258
],
2197
2259
]);
2198
2260
2199
-
If your application accepts images uploaded by your users, you may use the `File` rule's `image` constructor method to indicate that the uploaded file should be an image. In addition, the `dimensions` rule may be used to limit the dimensions of the image:
Even though you only need to specify the extensions when invoking the `types` method, this method actually validates the MIME type of the file by reading the file's contents and guessing its MIME type. A full listing of MIME types and their corresponding extensions may be found at the following location:
2214
2265
2215
-
> [!NOTE]
2216
-
> More information regarding validating image dimensions may be found in the [dimension rule documentation](#rule-dimensions).
For convenience, minimum and maximum file sizes may be specified as a string with a suffix indicating the file size units. The `kb`, `mb`, `gb`, and `tb` suffixes are supported:
2222
2272
2223
2273
```php
2224
-
File::image()
2274
+
File::types(['mp3', 'wav'])
2225
2275
->min('1kb')
2226
-
->max('10mb')
2276
+
->max('10mb');
2227
2277
```
2228
2278
2229
-
<aname="validating-files-file-types"></a>
2230
-
#### File Types
2279
+
<aname="validating-files-image-files"></a>
2280
+
#### Validating Image Files
2231
2281
2232
-
Even though you only need to specify the extensions when invoking the `types` method, this method actually validates the MIME type of the file by reading the file's contents and guessing its MIME type. A full listing of MIME types and their corresponding extensions may be found at the following location:
2282
+
To validate that uploaded files are images, you can use the `File` rule's `image` constructor method. The `File::image()` rule ensures that the file under validation is an image (jpg, jpeg, png, bmp, gif, svg, or webp):
You may also validate the dimensions of an image. For example, to validate that an uploaded image is at least 1000 pixels wide and 500 pixels tall, you may use the `dimensions` rule:
2301
+
2302
+
```php
2303
+
use Illuminate\Validation\Rule;
2304
+
use Illuminate\Validation\Rules\File;
2305
+
2306
+
File::image()->dimensions(
2307
+
Rule::dimensions()
2308
+
->maxWidth(1000)
2309
+
->maxHeight(500)
2310
+
)
2311
+
```
2312
+
2313
+
> [!NOTE]
2314
+
> More information regarding validating image dimensions may be found in the [dimension rule documentation](#rule-dimensions).
0 commit comments