如何使用来自两个不同表的旧信息自动填充编辑表单?

问题描述 投票:0回答:1

我有这个表格“编辑环”。编辑一个“tache”会影响两个表user和technicien,当我选择编辑tache时,编辑表单会自动填充来自技术表的信息,但与表用户相关的字段不会自动填充。我如何使用两个表中的信息自动填充表单?谢谢。

enter image description here

调节器

public function edit($id)
{
    $technicien=technicien::find($id);
    $user = user::orderBy('id', 'asc')->get();
    return view('technicien.edit',['moyenne_avis'=>$technicien],['actif'=>$technicien],['user_id'=>$technicien])->with('users', $user );
}

public function update(Request $request, $id)
{
    // do some request validation
    $technicien=technicien::find($id);
    $technicien->update($request->all());
    return redirect('technicien');
}

视图

@extends('Layouts/app')
@extends('Layouts.master')
@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-10">
            <h1>Modifier Tache</h1>
        <form action="{{ route('technicien.update', $actif->id , $moyenne_avis->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') ? old('nom') : $actif->nom }}" required autofocus>
            </div>
            <div class="form-group">
                <label for="">Prenom</label>
                <input id="nom" type="text" class="form-control" name="nom" value="{{ old('nom') ? old('nom') : $actif->nom }}" required autofocus>
            </div>

            <div class="form-group">
                <label for="">moyenne Avis</label>
                <input type="text"  name ="moyenne_avis" class="form-control"value ="{{$moyenne_avis->moyenne_avis}}" >
            </div>
            <div class="form-group">
                <label for="">Etat Technicien</label>
                <input type="text"  name ="actif" class="form-control"value ="{{$actif->actif}}" >
            </div>



            <div class="form-group">

                <input type="submit" value = "enregistrer" class="form-control btn btn-primary">
            </div>
        </form>
    </div>
</div>
@endsection

路线

Route::get('/technicien/{id}/edit', 'TechnicienController@edit');
Route::put('/technicien/{id}', 'TechnicienController@update')-
>name('technicien.update');
laravel laravel-5.2 laravel-5.1 laravel-5.3
1个回答
0
投票
$user = user::find($id);

如果使用控制器上的一个id检索它们,请告诉它们之间的关系。

并且在您看来,我没有看到检查旧的原因,因为它尚未更新!使用

{{$user->nom)}}
© www.soinside.com 2019 - 2024. All rights reserved.