I want to validation a users information like date of birth for that i have used following line of statement in validation, But how do i make it dynamic so users minimum age could be 13. below that can't register?
return Validator::make($data, [
'first_name' => 'required|string|max:255',
'last_name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6',
'date_of_birth' =>'required|date|before:2011-06-08',
]);
According to the docs at https://laravel.com/docs/5.5/validation, you should be able to use any valid string that works with the strtotime() function. In this case strtotime('13 years ago') is a valid descriptor for the dynamic date you are after. Hence, the following should work:
return Validator::make($data, [
'first_name' => 'required|string|max:255',
'last_name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6',
'date_of_birth' =>'required|date|before:13 years ago',
]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With