我正在尝试在laravel中编辑表单输入。当我单击编辑按钮时,它仅显示表单,而不会加载已选择的值。我该如何解决该问题?谢谢
视图编辑页面中的代码:
Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Collecting gi
ERROR: Could not find a version that satisfies the requirement gi (from versions: none)
ERROR: No matching distribution found for gi
我的控制器中的代码
<form action="/arquiteturas/update" method="post" role="form" class="form-horizontal">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group {{$errors->has('combo_produto')? ' has-error' : '' }}">
<label class="col-md-2 control-label">Produto</label>
<div class="col-md-8">
<select class="form-control search-select" name="combo_produto" id="combo_produto">
<option value="0">Selecione</option>
@foreach($produtos as $value)
<option @if(old('combo_produto')==$value->id){{'selected'}}@endif value='{{$value->id}}'>{{$value->nome}}</option>
@endforeach
</select>
<span class="help-block">
@if($errors->has('combo_produto'))
@foreach ($errors->get('combo_produto') as $error)
<b>{{$error}}</b>
@endforeach
@endif
</span>
</div>
</div>
<!--Projet. Work on it later to fix list-->
<div class="form-group {{$errors->has('combo_projeto')? ' has-error' : '' }}">
<label class="col-sm-2 control-label">Projeto</label>
<div class="col-sm-8">
<select class="form-control search-select" name="combo_projeto" id="combo_projeto">
<option value="0">Selecione</option>
@if(isset($projetos))
@foreach($projetos as $p)
<option @if(old('combo_projeto')==$p->id){{'selected'}}@endif value='{{$p->id}}'>{{$p->nome}}</option>
@endforeach
@endif
</select>
<span class="help-block">
@if($errors->has('combo_projeto'))
@foreach ($errors->get('combo_projeto') as $error)
<b>{{$error}}</b>
@endforeach
@endif
</span>
</div>
</div>
<!--Projeto Fim-->
<!--Link-->
<div class="form-group {{$errors->has('txt-link[]')? ' has-error' : '' }}">
<label class="col-sm-2 control-label">Link da Arquitetura no Git</label>
<div class="col-sm-8">
<!--Table -->
<table border="0" id="dynamic_field">
<tr>
<td><input type="text" placeholder="Digite o link da arquitetura" class="form-control"
id="txt-link[]" name="txt-link[]" value="{{old('txt-link[]')}}" style= width:730px;>
@if($errors->has('txt-link.0'))
@foreach ($errors->get('txt-link.0') as $message)
<span class="help-block" style="margin-top:5px; margin-bottom:-5px; color:rgb(170, 56, 56)"><b>{{ $message }}</b></span>
@endforeach
@endif
</td>
<td><button type="button" name="add" id="add"
<a class="btn btn-primary"><i class="fa fa-plus"></i>
</a></button>
</td>
</tr>
</table>
<!--Table Fim -->
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-2 col-sm-offset-6">
<a class="form-control btn btn-primary" href="/arquiteturas">
<i class="fa fa-arrow-circle-left"></i> Cancelar
</a>
</div>
<div class="col-sm-2">
<button type="submit" class="form-control btn btn-primary">Salvar</button>
</div>
</div>
单击“编辑”按钮时,需要加载用户选择的旧值。
答案 0 :(得分:0)
您可以将a default value作为第二个参数传递给old
函数:
<select class="form-control search-select" name="combo_produto" id="combo_produto">
<option value="0">Selecione</option>
@foreach($produtos as $value)
<option @if(old('combo_produto', $arquitetura->combo_produto)==$value->id){{'selected'}}@endif value='{{$value->id}}'>{{$value->nome}}</option>
@endforeach
</select>