Laravel validation - input must be one of items in array

前端 未结 2 823
清酒与你
清酒与你 2021-02-20 08:43

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\         


        
相关标签:
2条回答
  • 2021-02-20 09:21

    There's in

    $rules = [
        'field_name' => "required|in:yes,no,maybe",
    ];
    
    0 讨论(0)
  • 2021-02-20 09:43

    Laravel 5.7

    use Illuminate\Validation\Rule;
    
    Validator::make($data, [
        'field_name' => [
            'required',
            Rule::in(['yes', 'no', 'maybe']),
        ],
    ]);
    
    0 讨论(0)
提交回复
热议问题