Validate array of inputs in form in Laravel 5.7

前端 未结 6 1370
生来不讨喜
生来不讨喜 2021-01-20 01:59

My form has the same input field multiple times. My form field is as follows:




        
6条回答
  •  深忆病人
    2021-01-20 02:54

    You can check it like this:

    $validator = Validator::make($request->all(), [
        "items"    => "required|array|min:1",
        "items.*"  => "required|string|distinct|min:1",
    ]);
    

    In the example above:

    • "items" must be an array with at least 1 elements.
    • Values in the "items" array must be distinct (unique) strings, at least 1 characters long.

提交回复
热议问题