Laravel validation - input must be one of items in

2019-04-07 18:58发布

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:

$rules = [
    'field_name' => "required|in_array('yes', 'no', 'maybe')",
];

2条回答
爷的心禁止访问
2楼-- · 2019-04-07 19:40

Laravel 5.7

use Illuminate\Validation\Rule;

Validator::make($data, [
    'field_name' => [
        'required',
        Rule::in(['yes', 'no', 'maybe']),
    ],
]);
查看更多
beautiful°
3楼-- · 2019-04-07 20:02

There's in

$rules = [
    'field_name' => "required|in:yes,no,maybe",
];
查看更多
登录 后发表回答