【发布时间】:2019-06-14 08:18:44
【问题描述】:
我有一个 select2,它列出了数据库表的所有项目。其中一项已被选中。在编辑模式下,如何显示已选择的项目并列出其余项目?
在控制器中:
$offertaheader = Offertaheader::find($id_offertaheader);
$clients = Client::all()->where('visibility',1)
->sortBy('nome');
return view('offertas.edit',compact('offertaheader','clients'));
IN VIEW BLADE:
<select class="form-control select2" name="id_cliente" style="width: 100%">
<optgroup label="<?php echo htmlentities(utf8_encode('CLIENTE'), 0, "UTF-8"); ?>">
<option></option>
@foreach($clients as $client)
<option value="{{$client->id}}" {{ (old('id_client', $client->id) == ($client ? $client->id : '') ? ' selected' : '') }}>{{$client->nome}}</option>
@endforeach
</select>
我希望必须显示已选择的项目,同时用户可以在刀片中更改它。我更喜欢避免使用 jquery 或 ajax 等前端编码。
【问题讨论】: