Laravel 验证 - 输入必须是数组中的项目之一
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30616622/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 11:42:30 来源:igfitidea点击:
Laravel validation - input must be one of items in array
提问by user3702861
Is there a built in validator in Laravel 5 that checks if value is in array of my whitelisted values sort of speak.. Something like:
Laravel 5 中是否有一个内置的验证器来检查值是否在我的白名单值数组中,有点像这样说:
$rules = [
'field_name' => "required|in_array('yes', 'no', 'maybe')",
];
回答by vijikumar
Laravel 5.7
Laravel 5.7
use Illuminate\Validation\Rule;
Validator::make($data, [
'field_name' => [
'required',
Rule::in(['yes', 'no', 'maybe']),
],
]);