我对获得选择的价值感到困惑。 如果我的验证系统错误。我想获取我的下拉列表的值。
<fieldset class="form-group {{ $errors->has('ville') ? 'has-error' : '' }}">
<label for="company-content">Ville</label>
<select name="fk_localite" id="fk_localite" class="form-control" required="required" value="{{ old('fk_localite')}}"/>
<option value="">Choix ville</option>
@foreach($localites as $localite)
<option value="{{$localite->id}}" {{ old('ville') == $localite->id ? {{ 'selected' }}>{{$localite->ville}}</option>
@endforeach
{!! $errors->first('fk_localite', '<span class="helpblock">:message</span>') !!}
</select>
</fieldset>
答案 0 :(得分:1)
首先,您需要修复此 bug :
来自
<option value="{{$localite->id}}" {{ old('ville') == $localite->id ? {{ 'selected' }}>{{$localite->ville}}</option>
收件人
<option value="{{$localite->id}}" {{ old('ville') == $localite->id ? 'selected' : '' }} >
{{$localite->ville}}
</option>
然后在控制器中获取选定的值:
$selected = $request->input('fk_localite');
//For example if selected item value was 123 now $selected is 123 .