我有这种形式" Modifier Technicien"我将使用它修改技术人员的信息,修改将影响我的数据库表用户和表技术人员的两个表。我希望我的表单能够自动填充我选择修改的技术人员的信息。谢谢
edit.blade.php
@extends('Layouts/app')
@extends('Layouts.master')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-10">
<h1>Modifier Technicien</h1>
<form action="{{ route('technicien.update', $moyenne_avis->id , $actif->id ) }}" method="post">
{{csrf_field()}}
{{ method_field('PATCH') }}
<div class="form-group">
<label for="">Nom</label>
<input id="nom" type="text" class="form-control" name="nom" value="{{ old('nom') }}" required autofocus>
@if ($errors->has('nom'))
<span class="help-block">
<strong>{{ $errors->first('nom') }}</strong>
</span>
@endif
</div>
<div class="form-group">
<label for="">Prenom</label>
<input id="prenom" type="text" class="form-control" name="prenom" value="{{ old('prenom') }}" required autofocus>
@if ($errors->has('prenom'))
<span class="help-block">
<strong>{{ $errors->first('prenom') }}</strong>
</span>
@endif
</div>
<div class="form-group">
<label for="">Telephone</label>
<input id="tel" type="text" class="form-control" name="tel" value="{{ old('tel') }}" required autofocus>
@if ($errors->has('tel'))
<span class="help-block">
<strong>{{ $errors->first('tel') }}</strong>
</span>
@endif
</div>
<div class="form-group">
<label for="">Mobile</label>
<input id="mobil" type="text" class="form-control" name="mobil" value="{{ old('mobil') }}" required autofocus>
@if ($errors->has('mobile'))
<span class="help-block">
<strong>{{ $errors->first('mobil') }}</strong>
</span>
@endif
</div>
<div class="form-group">
<label for="">Role</label>
<input id="role" type="text" class="form-control" name="role" value="{{ old('role') }}" required autofocus>
@if ($errors->has('role'))
<span class="help-block">
<strong>{{ $errors->first('role') }}</strong>
</span>
@endif
</div>
<div class="form-group">
<label for="">Moyenne Avis</label>
<input type="text" name ="moyenne_avis" class="form-control"value="{{old('moyenne_avis')}}">
</div>
<div class="form-group">
<div class="form-group">
<label for="">Etat</label>
<input type="text" name ="actif" class="form-control"value="{{old('actif')}}">
</div>
<div class="form-group">
<input type="submit" value = "enregistrer" class="form-control btn btn-primary">
</div>
</form>
</div>
</div>
@endsection
控制器
public function edit($id)
{
$technicien=technicien::find($id);
$users = user::orderBy('id', 'asc')->get();
return view('technicien.edit',['moyenne_avis'=>$technicien],['actif'=>$technicien],['user_id'=>$technicien])->with('user', $users);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
technicien::where('id', $id)->update($request->all());
return redirect('technicien/edit');
}
route.php
Route::get('/technicien/{id}/edit', 'TechnicienController@edit');
Route::put('/technicien/{id}', 'TechnicienController@update')-
>name('technicien.update');
答案 0 :(得分:2)
/**
* Retrieve an old input item.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
function old($key = null, $default = null)
{
return app('request')->old($key, $default);
}
old()
函数有2个参数。第一个来自会话,第二个是默认。
所以你可以使用:
<input id="nom" type="text" class="form-control" name="nom" value="{{ old('nom', $actif->nom) }}" required autofocus>