多选下拉菜单仅将最后选定的值保存到数据库-Laravel
我想将用逗号分隔的多选下拉选择名称保存到数据库中。使用“我的代码”,它只将最后选定的值保存到数据库中 Blade.php多选下拉菜单仅将最后选定的值保存到数据库-Laravel,laravel,multi-select,Laravel,Multi Select,我想将用逗号分隔的多选下拉选择名称保存到数据库中。使用“我的代码”,它只将最后选定的值保存到数据库中 Blade.php <div class="form-group"> <select name="team[]" id="team" class="selectpicker" multiple> @foreach ($tdropdown as $tdrop =>$id)
<div class="form-group">
<select name="team[]" id="team" class="selectpicker" multiple>
@foreach ($tdropdown as $tdrop =>$id)
<option value="{{$id}}">{{$tdrop}}</option>
@endforeach
</select>
</div>
当Ivar\u dump($result)时代码>它输出所有选定值,如下所示
string(2) "Team one" string(2) "Team two"
但是上面的代码只保存最后选择的值,这意味着数据库中只有“第二组”。请帮助我将所有选定值保存到数据库。谢谢。更改$tarray=$request->input('team')代码>到$tarray=$request->team代码>还有一件事。我想在edit.blade.php中获得multi-select下拉列表的选定旧值上面的问题中提到了multi-select下拉列表代码。我尝试了很多上网的方法,但都失败了。谢谢你的帮助。
$teams = $request->input('team', []);
$employee->team = DB::table('teams')
->whereIn('id', $teams) // only find the ids we received
->pluck('name') // only get the 'name' column
->implode(','); // implode into a comma separated list
$employee->save();
$teams = $request->input('team', []);
$employee->team = DB::table('teams')
->whereIn('id', $teams) // only find the ids we received
->pluck('name') // only get the 'name' column
->implode(','); // implode into a comma separated list
$employee->save();