Reputation: 1439
How do I validate a date in such a way that it only accepts today and any date older than today? I know before:today
accepts older dates while after:today
accepts dates starting tomorrow on-wards.
$rules = [
'start_at' => 'required|date|date_format:Y-m-d|after:yesterday',
'end_at' => 'required|date|date_format:Y-m-d|after:start_at',
];
I want to be able to start a task today and end today.
Upvotes: 2
Views: 1637
Reputation: 5958
From my understanding, you want the end_at
to on the same date or after start_at
but not before start_at
.
public function rules()
{
return [
'start_at' => 'required|date|date_format:Y-m-d|after:yesterday',
'end_at' => 'required|date|date_format:Y-m-d|after:' . \Carbon\Carbon::parse($this->start_date)->subDay()->toDateString(),
];
}
What I have done so far, The end_at
need to be relevant with the start_at
(same or after the start_at
).
strtotime
PHP function.Upvotes: 6