get id on slect box

Posted 6 months ago by chagouani

I have 2 interface the first to create a "technicien" the 2nd it's given him a "tarification" of hit "tache" so after finishing to create our technicien button validate us rederict to the interface tarifciation which takes as parameter id techncien_id automatically on à dynamic combobox

I managed to recover technicien_id but my problem is that I have relative combobox in the 2nd interface so I have to reselected the technician to take the technicien_id

tarificationcontroller.php

public function create($technicien_id)   
{
    $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);
}

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-"' ; $.each(res.metiers,function(index,item) { html+=''+item.libelle_metier+''; }); $('#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="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?}', 
    '[email protected]');

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.