Level 3
I think you have a typo, ref_country_id vs country_id.
I have two table as like country and school. so now what i am gonna do that, in school there is a country_id as fk.now when i select country all country appear but not showing schools under that id.
controller: query for getting school.
$countries = Input::get('ref_country_id');
$schoolList = LanguageSchoolModel::where('ref_country_id','=',$countries)->get();
return response()->json($schoolList);
Route:
Route::get('json-school','Adminpanel\school@lng_school_list');
JS for dependent dropdown:
$(document).ready(function(){
$('#countries').on('change',function(e){
console.log(e);
var country_id = e.target.value;
$.get('json-school?country_id=' +country_id,function(data){
console.log(data);
var option='<option value="0" disable="true" selected="true">Select city</option>';
$.each(data, function( index, schoolObj){
option+='<option value="'+schoolObj.id+'" >'+schoolObj.name+'</option>';
})
$('#schoolList').html(option);
$('#schoolList').selectpicker('refresh');
})
})
})
Nothing found when access this : json-school?country_id=2
Please or to participate in this conversation.