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