x1c 0d1x我想单独获取每个lab_test的成本,但它给了我所有的成本。我尝试使用->first(); and ->first(['cost']);在控制器中,但得到类似“响应内容必须是实现__toString()的字符串或对象”的错误,对象“给定”。我正在我的项目中实现依赖下拉选择框。
Controller Test.php
class Test extends Controller
{
public function cost(Request $request){
$lab_data = \DB::table('lab_category')->select('lab_category_id','category_name')->get();
return view('pages/medicinecost')->with('lab_category',$lab_data);
}
public function costSub(Request $request){
$get_lab_cat_id = $request->get('labCategId');
$lab_sub_data = \DB::table('lab_sub_category')
->leftJoin('lab_category','lab_category.lab_category_id','=','lab_sub_category.category_id')
->where('lab_category_id', $get_lab_cat_id)
->select('sub_category_name','lab_sub_category_id')->get();
return $lab_sub_data;
}
public function costTest(Request $request){
$get_lab_sub_id = $request->get('labSubId');
$lab_test_data = \DB::table('lab_test')
->leftJoin('lab_sub_category','lab_sub_category.lab_sub_category_id'
,'=','lab_test.sub_category_id')
->where('sub_category_id',$get_lab_sub_id)
->where('hide',0)
->select('lab_name','lab_test_id')->get();
return $lab_test_data;
}
public function labTestprice(Request $request){
$get_lab_test_id = $request->get('labtid');
$cost = \DB::table('lab_test')
->leftJoin('lab_sub_category','lab_sub_category.lab_sub_category_id','=','lab_test.sub_category_id')
->where('lab_test_id',$get_lab_test_id)
->orWhere('hide',0)
->select('cost','lab_test_id')->get();
// dd($cost);
return $cost;
}
}
字符串
Route.php
Route::get('labdetails','Test@cost');
Route::post('get_lab_sub','Test@costSub');
Route::post('get_lab_sub_cat','Test@costTest');
Route::post('get_lab_cost_rs','Test@labTestprice');
型
medicinecost.blade.php
<body>
<h1><p>Lab Cost</p></h1><br>
<div class="container">
<div class="col-lg-3">
<div class="form-group">
<select name="labCat" id="labC" class="form-control">
<option value="0" disabled="true" selected="true">Select Lab Category</option>
@if(isset($lab_category))
@foreach($lab_category as $lb)
<option value="{{$lb->lab_category_id}}">{{$lb->category_name}}</option>
@endforeach
@endif
</select>
</div>
<div class="form-group">
<select name="labSub" id="labS" class="form-control">
<option value="0" disabled="true" selected="true">Select Lab Sub Category</option>
</select>
</div>
<div class="form-group">
<select name="labTest" id="labT" class="form-control">
<option value="0" disabled="true" selected="true">Select Lab Test</option>
</select>
</div>
<div class="col-md-2"><span id="loader"><i class="fa fa-spinner fa-3x fa-spin"></i></span></div>
</div>
</div>
<div>
<p id="testCost"></p>
</div>
<script>
$(document).ready(function() {
$('#labC').on('change', function(){
var labCategId = $(this).val();
if(labCategId) {
$.ajax({
processing : 'true',
serverSide : 'true',
url: 'get_lab_sub',
type:"POST",
data : {labCategId:labCategId,"_token":"{{ csrf_token() }}"},
dataType:"json",
success:function(data) {
if(data){
$('#labS').empty();
$.each(data, function(key, value){
$('#labS').append('<option value="'+value.lab_sub_category_id+'">' + value.sub_category_name + '</option>');
});
}
},
});
} else {
$('select[name="labS"]').empty();
}
});
$('#labS').on('change' ,function () {
var labSubId = $(this).val();
if(labSubId){
$.ajax({
processing : 'true',
serverSide : 'true',
url :'get_lab_sub_cat',
type:"POST",
data :{ labSubId:labSubId,"_token":"{{ csrf_token() }}"},
dataType: "json",
success:function (data) {
if(data){
$('#labT').empty();
$.each(data, function(key, value){
$('#labT').append('<option value="'+ value.sub_category_id +'">' + value.lab_name + '</option>');
});
}
else {
$('#labT').empty();
}
}
});
}
})
$('#labT').on('change' ,function () {
var lab_test_cost_id = $(this).val();
if(lab_test_cost_id){
$.ajax({
processing : 'true',
serverSide : 'true',
url :'get_lab_cost_rs',
type:"POST",
data :{ labtid:lab_test_cost_id,"_token":"{{ csrf_token() }}"},
dataType: "json",
success:function (data) {
if(data){
//$('#labT').empty();
$.each(data, function(key, value){
$('#testCost').append('<p value="'+value.lab_test_id +'"> '+ value.cost + '</p>');
//$('#testCost').append('<p value="'+value.lab_test_id+'">'+value.cost+'</p>');
});
}
}
});
}
});
});
</script>
</body>
型
每当我从第三个下拉列表中选择lab_test时,它应该显示该perticuler lab_tests的成本,但不是显示所有成本。
2条答案
按热度按时间zbwhf8kr1#
试试这个:
字符串
ee7vknir2#
从属下拉菜单编辑
字符串