Reputation: 163
i have this form "Modifier Technicien" with which I will modify the information of a technician, the modifications will affect two tables of my database table user and table technician. I want my form to be autofilled with the information of the technician I chose to modify. Thank you
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
controller
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');
Upvotes: 0
Views: 841
Reputation: 795
/**
* 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()
function has 2 params. First one is from session, second one is default.
So you can use like:
<input id="nom" type="text" class="form-control" name="nom" value="{{ old('nom', $actif->nom) }}" required autofocus>
Upvotes: 2