If you have a lot of sub categories, pull them in via ajax after sector is selected
If you don't have many sub categories, load them all in and hide/show based on selected sector
elite123 said:
If you have a lot of sub categories, pull them in via ajax after sector is selected
If you don't have many sub categories, load them all in and hide/show based on selected sector
Thank you for the reply... I'm new to laravel. Can you guide me to integrate ajax?
Finally done it... :)
MyController.php
public function getSubCategories(Request $request, $id){
if($request->ajax()){
$sector = Sector::find($id);
return Response::json( $sector->category );;
}
}
Script.js
//get subcateogries according to sector selection
$("#sector_id").change(function(){
$.get("submission/getSubCategories/"+ $(this).val(), function(data){
$element = $("#category_id");
$element.removeAttr('disabled');
$(data).each(function(){
$element.append("<option value='"+ this.id +"'>"+ this.name +"</option>");
});
});
})
Route.php
Route::get('submission/getSubCategories/{id}', 'SubmissionController@getSubCategories'); //AJAX request to get sub categories
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community