Skip to content

Commit 00ed662

Browse files
[12.x] feat: add now methods to Date rule (#58059)
* feat: add now methods to Date rule * formatting --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 735778d commit 00ed662

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/Illuminate/Validation/Rule.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,14 @@ public static function date()
184184
return new Date;
185185
}
186186

187+
/**
188+
* Get a datetime rule builder instance.
189+
*/
190+
public static function dateTime(): Date
191+
{
192+
return (new Date)->format('Y-m-d H:i:s');
193+
}
194+
187195
/**
188196
* Get an email rule builder instance.
189197
*

src/Illuminate/Validation/Rules/Date.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,38 @@ public function todayOrAfter(): static
6464
return $this->afterOrEqual('today');
6565
}
6666

67+
/**
68+
* Ensure the date is in the past.
69+
*/
70+
public function past(): static
71+
{
72+
return $this->before('now');
73+
}
74+
75+
/**
76+
* Ensure the date is in the future.
77+
*/
78+
public function future(): static
79+
{
80+
return $this->after('now');
81+
}
82+
83+
/**
84+
* Ensure the date is now or in the past.
85+
*/
86+
public function nowOrPast(): static
87+
{
88+
return $this->beforeOrEqual('now');
89+
}
90+
91+
/**
92+
* Ensure the date is now or in the future.
93+
*/
94+
public function nowOrFuture(): static
95+
{
96+
return $this->afterOrEqual('now');
97+
}
98+
6799
/**
68100
* Ensure the date is before the given date or date field.
69101
*/

0 commit comments

Comments
 (0)