Reputation: 971
I would like to set a due date (dynamic), the person can register if it is 17to 60 years old.
I have tried this:
'date_naissance' => 'required|date|after:1960|before:2003-01-01'
But, I have to change the values each years.It is possible to improve this?
Thank you
Upvotes: 1
Views: 167
Reputation: 9161
You can try something like this:
$year = (int)date("Y");
'date_naissance' =>
'required|date|after:'.($year - 59).'|before:'.($year - 16).'-01-01'
Or a bit more precise:
'date_naissance' =>
'required|date|after:'.date('Y-m-d', strtotime('-59 year')).'|before:'.date('Y-m-d', strtotime('-16 year'))
It should work also with this:
'date_naissance' =>
'required|date|after:-59 year|before:-16 year'))
Upvotes: 1