如何在验证阶段检查传递的值是否等于我想要的值。
$rules = [
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6',
'admin_code' => 'required|<the value must be equals to this code "admin">',
];
答案 0 :(得分:1)
假设您要确保 admin_code 始终等于 admin ,您可以使用这样的laraval验证器:
正则表达式:/ ^([a-z])+ $ / i字段值必须与提供的常规值匹配 表达
$rules = [
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6',
'admin_code' => 'required|regex:^admin$>',
];
In:small,medium,large确保该值包含在 提供的值列表。
$rules = [
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6',
'admin_code' => 'required|in:admin>',
];