Laravel 如何使用上一个表单中的id自动填写表单

Laravel 如何使用上一个表单中的id自动填写表单,laravel,laravel-5,laravel-4,laravel-5.2,laravel-5.1,Laravel,Laravel 5,Laravel 4,Laravel 5.2,Laravel 5.1,单击“添加”按钮后,我尝试使用上一张表单中的techinician id自动填充表单。 我有一份技术人员名单,每个技术人员都有多个与他相关的“tarification环节” 当我按下add(添加)按钮时,我被引导到表格中,以在此表格中添加“tarification tache”,我必须选择技师。因此,我希望表格自动填写有问题的技术人员的ID,这来自上一张表格 @extends('Layouts/app') @extends('Layouts.master') @section('content'

单击“添加”按钮后,我尝试使用上一张表单中的techinician id自动填充表单。 我有一份技术人员名单,每个技术人员都有多个与他相关的“tarification环节” 当我按下add(添加)按钮时,我被引导到表格中,以在此表格中添加“tarification tache”,我必须选择技师。因此,我希望表格自动填写有问题的技术人员的ID,这来自上一张表格

@extends('Layouts/app')
@extends('Layouts.master')
@section('content')
@if(count($errors))
<div class="alert alert-danger" role="alert">
<ul>
@foreach($errors ->all() as $message)
<li>{{$message}}</li>
@endforeach
</ul>
</div>
@endif
<script 
src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>



<script type="text/javascript">

var getMetiersByTechnicienUrl = "{{url('/metiersbytechnicien')}}";
var getTachesByMetierUrl = "{{url('/tachesbymetier')}}";

//console.log(getMetiersByTechnicienUrl,getTachesByMetierUrl,
getTarificationsByTacheUrl);
function getMetiersByTechnicien(val) {
if(val.length>0) {
    var technicien_id = val;
    $.get(getMetiersByTechnicienUrl+'/'+technicien_id,function(res) {
        var html = '<option value="">-Select-</option>' ;
        $.each(res.metiers,function(index,item) {
            html+='<option 
value="'+item.id+'">'+item.libelle_metier+'</option>';
        });
        $('#metiers').html(html);

    });
 }
 }
    function getTachesByMetier(val) {
     if(val.length>0) {
    var metier_id = val;
    $.get(getTachesByMetierUrl+'/'+metier_id,function(res) {
        var html = '<option value="">-Select-</option>' ;
        $.each(res.taches,function(index,item) {
            html+='<option 
value="'+item.id+'">'+item.libelle_tache+'</option>';
        });
        $('#taches').html(html);

    });
    }
    }

    </script>
<div class="container">
    <div class="row"></div>
    <div class="col-md-12">
    Z
    <div class="col-md-10">
    <h1>Tarification tache</h1>
    <form action=" {{url ('tarification')  }}" method="post">
     {{csrf_field()}}

    <div class="form-group">
     <label for="technicien">Technicien</label>
        <select onchange="getMetiersByTechnicien(this.value)" 
name="technicien_id" 
    id="technicien" class="form-control">
            <option value="">-Select-</option>
            @foreach($technicien as $t)
                <option value="{{$t->id }}">
                    {{$t->user->nom}}
                </option>
            @endforeach
        </select>
    </div>
    <div class="form-group">
    <div class="col-md-12">
            <div class="col-md-4">
    <label>Metier: </label>
    <select onchange="getTachesByMetier(this.value)" style="width: 
200px"    
    class="productm form-control" id="metiers">
         <option value="">-Select-</option>


    </select>
            </div>
            <div class="col-md-4">
                <label>tache: </label>
                <select style="width: 200px" class="productname form- 
control" 
name="tache_id" id="taches">
                    <option value="">-Select-</option>
                </select>
            </div>
            <div class="col-md-4">
                <label>tarification: </label>
                <input style="width: 200px" class="productname form- 
 control" type="text"  
 name ="Tarif" class="form-control" value="{{old('tarif')}}">


            </div>


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

@endsection
@extends('Layouts/app')
@扩展('Layouts.master')
@节(“内容”)
@如果(计数($errors))
    @foreach($errors->all()作为$message)
  • {{$message}}
  • @endforeach
@恩迪夫 var getMetiersByTechnicienUrl=“{url('/metiersbytechnicien')}”; var getTachesByMetierUrl=“{url('/tachesbymetier')}”; //console.log(getMetiersByTechnicienUrl、getAchesbymetierUrl、, 通过链接URL获取分类信息; 函数getMetiersByTechnicien(val){ 如果(值长度>0){ var technicien_id=val; $.get(getMetiersByTechnicienUrl+'/'+technicien_id,函数(res){ var html='-Select-'; $。每个(资源、功能(索引、项目){ html+=''+项。诽谤者+''; }); $('#metiers').html(html); }); } } 函数getTachesByMetier(val){ 如果(值长度>0){ var metier_id=val; $.get(getCachesByMetierUrl+'/'+metier_id,函数(res){ var html='-Select-'; $。每个(资源链接、功能(索引、项目){ html+=''+项。诽谤链接+''; }); $('#taches').html(html); }); } } Z 焦油化环节 {{csrf_field()}} 技术员 -挑选- @外汇($t) {{$t->user->nom} @endforeach 梅蒂埃: -挑选- 环节: -挑选- 焦油化: @端部
tarificationcontroller:

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\tarificationtache;
use App\technicien;
use App\tache;
use App\metier;

class TarificationController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$Listtache=tache::orderBy('libelle_tache')->get();
$Listtarification=tarificationtache::all();
return view('tarification.index',['tarification'=>$Listtarification]);
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
$technicien = technicien::orderBy('id','desc')->get();
$taches = Tache::orderBy('libelle_tache', 'asc')->get();
$metiers = Metier::orderBy('libelle_metier', 'asc')->get();
return view('tarification.create')->with('taches', $taches)- 
>with('technicien', $technicien)- 
>with('metiers', $metiers);
}

/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 *@return \Illuminate\Http\Response
 */
 public function store(Request $request)
 {

$tarification = new tarificationtache();
$tarification ->tache_id = $request->input('tache_id');
$tarification ->Tarif =$request->input('Tarif');
$tarification->save();
$tarification->techniciens()->attach($request->technicien_id);
return redirect('technicien');  }

/**
* Display the specified resource.
*
* @param  int  $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}

/**
* Show the form for editing the specified resource.
*
* @param  int  $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$tache=Tache::find($id);
return view('tache.edit',['libelle_tache'=>$tache],['Tarif'=>$tache], 
['metier_id'=>$tache]);
}

 /**
 * Update the specified resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function update(Request $request, $id)
{
//
}

 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
public function destroy($id)
{
$tache =Tache::find($id);
$tache->delete();

return redirect('tache');
}
public function getTarificationsByTache($tache_id)
{
$t =tache::find($tache_id);
return response()->json(['tarifications' => $t->tarificationtache]);
}

您可以通过添加javascript和ajax来实现这一点,或者通过在path.Route::get('tarification/create/{technicien_id?}'中添加技术人员的id来刷新页面TarificationController@create'); 公共函数create($technicien\u id=null)-选择-@foreach($technicien as$t)id==$technicien\u id?“selected=“selected”:“”}>{{{$t->user->nom}}@endforeach@ied3vil在尝试上面的代码时,我得到了这个错误“未定义的变量:technicien\u id(视图:C:\xampp\htdocs\projet\resources\views\tarification\create.blade.php)”