dpge74512
dpge74512
2015-02-04 23:53

在Laravel中显示输入数组的验证错误

  • laravel
  • php
  • validation

I am submitting an array of inputs to my controller like so:

<input id="box-1-nickname" name="box-nickname[]" class="form-control" type="text" placeholder="Required">
<input id="box-2-nickname" name="box-nickname[]" class="form-control" type="text" placeholder="Required">

I am doing some validation like this:

$validator = Validator::make(Input::all(), array(
        'supplies-count' => 'required|in:0,1,2,3,4',
    ));

$arrayValidator = Validator::make(Input::all(), []);

$arrayValidator->each('box-nickname', ['required|min:1|max:60']);

if( $validator->fails() || $arrayValidator->fails() ) {
    return Redirect::route('route-2')
           ->withErrors($arrayValidator)
           ->withInput();
}

The problem is when I try to check the errors like this it doesn't work:

if( $errors->has('box-1-nickname') ) { echo ' has-error'; }
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答

为你推荐