我有一个“ tarificationtache”接口,在这个接口中,“ technicien”可以为其“ taches”定价,而每个“ tache”都有一个“ tarif”定价, 我想检查这个'tache'是否有这个'technicien'的'tarif',如果是的话,它会创建一个消息'tarifi存在'。
表格税单
Schema::create('tarificationtaches', function (Blueprint $table) {
$table->increments('id');
$table->float('tarif', 8,2);
$table->integer('tache_id')->unsigned();
$table->foreign('tache_id')->references('id')->on('taches');
$table->integer('technicien_id')->unsigned();
$table->foreign('technicien_id')->references('id')-
>on('techniciens');
$table->datetime('deleted_at')->nullable();
$table->timestamps();
});
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>
@foreach($metiers as $metier)
<option value={{$metier->id}}>{{$metier->libelle_metier}}</option>
@endforeach
</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
控制器
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);
}
/**
* 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'); }