我想验证用户信息,例如出生日期,因为我在验证中使用了以下语句行,但是如何使其动态,以便用户的最低年龄可以为 13 岁。低于该年龄的用户无法注册?
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',
]);
根据文档https://laravel.com/docs/5.5/validation,您应该能够使用与 strtotime() 函数配合使用的任何有效字符串。在这种情况下, strtotime('13 年前') 是您所追求的动态日期的有效描述符。因此,以下内容应该有效:
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',
]);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)