无法从Laravel 5.3的注册表中获取数组

时间:2016-09-30 23:50:45

标签: php laravel laravel-5 laravel-5.3

我正在使用Laravel 5.3 auth:make registration form,我的表单中有一个多选项,它返回所选行的计数而不是带有值的数组。

那是我dd($ data)时回来的东西:

 array:10 [▼
      "_token" => "mBTBYC4yHsI0Ph1Hmj7p6MSstOCRM3cDkCoSZH4b"
      "first_name" => "User"
      "last_name" => "Family"
      "class" => "Software Engineer"
      "year" => "0"
      "tags" => "1" -> that should be an array.
      "phone" => "55555555"
      "email" => "test@test.com"
      "password" => "123123"
      "password_confirmation" => "123123"
    ]

我想在html中解决这个问题:

<div class="form-group{{ $errors->has('tags') ? ' has-error' : '' }}">
    {!! Form::select('tags[]', $tags , null , ['class' => 'form-control' , 'multiple' , 'id'=>'tags' , 'name' => 'tags']) !!}
    @if ($errors->has('tags'))
        <span class="help-block">
            <strong>{{ $errors->first('tags') }}</strong>
        </span>
    @endif
</div>

1 个答案:

答案 0 :(得分:0)

我认为问题在于你不给它们(“tags []”)一个将多个数据保存到数组中的键。这是我使用复选框{!! Form::checkbox('tag_id[]',$tag->id, null, ['class'=>'tag_id']) !!}处理tags数组的方法,检查第二个参数,我将值加载到tag_id []数组内的Id中。