Skip to content

Commit c7f4f79

Browse files
committed
fluent date rules
1 parent dbb8b04 commit c7f4f79

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

validation.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,11 +1062,36 @@ Instead of passing a date string to be evaluated by `strtotime`, you may specify
10621062

10631063
'finish_date' => 'required|date|after:start_date'
10641064

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+
10651081
<a name="rule-after-or-equal"></a>
10661082
#### after\_or\_equal:_date_
10671083

10681084
The field under validation must be a value after or equal to the given date. For more information, see the [after](#rule-after) rule.
10691085

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+
10701095
<a name="rule-alpha"></a>
10711096
#### alpha
10721097

@@ -1144,11 +1169,36 @@ While the `bail` rule will only stop validating a specific field when it encount
11441169

11451170
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`.
11461171

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+
11471188
<a name="rule-before-or-equal"></a>
11481189
#### before\_or\_equal:_date_
11491190

11501191
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`.
11511192

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+
11521202
<a name="rule-between"></a>
11531203
#### between:_min_,_max_
11541204

@@ -1193,6 +1243,15 @@ The field under validation must be equal to the given date. The dates will be pa
11931243

11941244
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.
11951245

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+
11961255
<a name="rule-decimal"></a>
11971256
#### decimal:_min_,_max_
11981257

0 commit comments

Comments
 (0)