我正在尝试根据Laravel 4中的先前选择框值填充选择框。我认为我有一个逻辑问题:S
我的Js`
$('#cat').change(function(){
category_id = $(this).val();
$('#secondcat').empty();
$.ajax({
type: 'GET',
url: '{{ URL::to('api/dropdown') }}',
data: 'category_id ='+category_id ,
contentType: "application/json; charset=utf-8",
dataType: "json",
success:function(veri){
$.each(veri,function(i,deger){
$('#secondcat').append('<option value="'+deger.id+'">' +deger.name+ '<option>' );
}); // each
},
error:function(x,hata){
alert("Hata Oluştu" +hata);
}
}); // ajax
}); // change`
路线
Route::get('api/dropdown','admin_BasvuruController@ajaxislemi');
我的BasvuruController中的ajaxislemi()方法:
public function ajaxislemi() {
$category_id = Input::get('category_id');
return Kampanya::where('category_id','==',$category_id)->get();
}
在查看我的表单中:
<select class="form-control" name="category_id" id="cat" >
<option value="" disabled selected> Please Select First </option>
@foreach($categories as $category)
<option value="{{ $category->id }}"> {{ $category->name }} </option>
@endforeach
</select>
<select name="kampanya_adi" class="form-control" id="secondcat" >
<option> </option>
</select>
答案 0 :(得分:0)
我相信这是你的问题:
return Kampanya::where('category_id','==',$category_id)->get();
你有一个双“==”。它应该是:
return Kampanya::where('category_id','=',$category_id)->get();