自动获取ID

时间:2018-06-08 12:42:10

标签: javascript php ajax laravel

我有2个接口,第一个创建"技术"第二,它给了他一个" tarification"击中" tache"所以在完成创建我们的技术按钮后验证我们对接口tarifciation的更新,该参数自动作为参数id techncien_id

我设法恢复了id,但我的问题是我在第二个界面中有相对的组合框,所以我必须重新选择技术人员才能使用technicien_id

这是我的第二个界面

enter image description here

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()
 {

 $Listtarifications=tarificationtache::with(['techniciens.user','tache'])- 
  >find($tarificationtache_id);

    return view('tarification.index',['tarifications'=>$Listtarifications]);


}


/**
 * Show the form for creating a new resource.
 *
 * @return \Illuminate\Http\Response
 */
public function create($technicien_id = null)   
{
    $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)- 
    >with('technicien_id', $technicien_id);
}

/**
 * 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->technicien_id = $request->input('technicien_id');
    $tarification->save();

    return redirect('technicien');  }

create.blade.php

@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">

       <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_id" class="form-control">
                       <option value="">-Select-</option>
                       @foreach($technicien as $t)
                              <option value="{{$t->id }}" {{ $t->id == 
    $technicien_id ? 'selected = "selected"' : '' }}>
                                    {{$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>






   <link 
    href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/    
    bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap- 
    datepicker/1.5.0/css/bootstrap-datepicker.css" rel="stylesheet">

    <script 
     src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"> 
    </script>

 <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap- 
 datepicker/1.5.0/js/bootstrap-datepicker.js"></script>
 @endsection

route.php

  Route::get('tarification/create/{technicien_id?}', 
  'TarificationController@create');

0 个答案:

没有答案
相关问题