如何用用户的旧信息自动填充“编辑"表单? [英] How to autofill Edit form with old Information of a user?

查看:76
本文介绍了如何用用户的旧信息自动填充“编辑"表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有这种形式的修改者技术人员",通过它可以修改技术人员的信息,修改将影响数据库表用户和表技术人员的两个表.我希望在表单中自动填写我选择修改的技术人员的信息.谢谢

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

控制器

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');

推荐答案

/**
 * 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个参数.第一个是会话,第二个是默认会话.

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>

这篇关于如何用用户的旧信息自动填充“编辑"表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆