2

在 Laravel 中,很容易验证数字输入 -

$rules = array('numericInput' => 'numeric');

但不确定如何验证数值数组。这可能是什么规则。或者 Laravel 的 Validator 类甚至可以实现吗?

例如-

此 HTML 表单将多个 Select 项目提交给 laravel 服务

<form .....>
  <select multiple="multiple" name="objectIdArr[]" >
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
  </select>
</form>

Laravel 得到了什么——

( [input] => Array ( [objectIdArr] => Array ( [0] => 1 [1] => 3 [2] => 5 ))

什么是规则!

请建议

4

1 回答 1

0

Laravel 3.x's validator doesn't handle arrays unfortunately as it expects each unique name to be a string.

You could however extend the validator class as a library (follow the docs for a decent example) and allow your extended class to recieve an array that then is broken out into strings and validated, if any of the strings fail validation the validator returns a failure with your custom message.

于 2013-03-19T16:26:53.017 回答