user11124425
user11124425

Reputation: 971

set a due date dynamic

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

Answers (2)

dparoli
dparoli

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

N. Djokic
N. Djokic

Reputation: 1036

You would need to make custom validation rule. Here is example how to do it: LINK

You will need to make method that takes person birth date and calculate his age. If age is greater then 17 it should return true.

Upvotes: 0

Related Questions