Home › Forums › Themeqx Advanced PhP Laravel Classified ads cms › Ajax does not work when filtering cities in Dashboard › Reply To: Ajax does not work when filtering cities in Dashboard
April 24, 2018 at 5:28 pm
#1546
![](https://www.themeqx.com/wp-content/uploads/2020/06/katherine2.jpg)
Katherine J. Bates
Keymaster
At LocationController.php
Remove getStatesData()
and getCityData()
and place below two mtehods instead of that
public function getStatesData(){
$searchTerm = \request('search.value');
if ($searchTerm){
$states = State::select('states.id', 'state_name', 'country_name', 'country_id')->leftJoin('countries', 'countries.id','=','states.country_id')->where('state_name', 'like', "%$searchTerm%");
}else{
$states = State::select('states.id', 'state_name', 'country_name', 'country_id')->leftJoin('countries', 'countries.id','=','states.country_id');
}
return Datatables::of($states)
->filterColumn('country_name', 'whereRaw', '1=1', [])
->addColumn('actions',function($state){
$html = '<a href="'.route('edit_state', $state->id).'" class="btn btn-primary"><i class="fa fa-edit"></i> </a>';
$html .= '<a href="javascript:;" data-id="'.$state->id.'" class="btn btn-danger deleteState"><i class="fa fa-trash"></i> </a>';
return $html;
})
->removeColumn('id', 'country_id')->make(true);
}
And
public function getCityData(){
$searchTerm = \request('search.value');
if ($searchTerm){
$cities = City::select('cities.id', 'cities.city_name', 'states.state_name', 'cities.state_id', 'countries.country_name', 'states.country_id')->leftJoin('states', 'states.id', '=', 'cities.state_id')->leftJoin('countries', 'countries.id', '=', 'states.country_id')->where('cities.city_name', 'like', "%{$searchTerm}%")->orderBy('city_name', 'asc');
}else {
$cities = City::select('cities.id', 'cities.city_name', 'states.state_name', 'cities.state_id', 'countries.country_name', 'states.country_id')->leftJoin('states', 'states.id', '=', 'cities.state_id')->leftJoin('countries', 'countries.id', '=', 'states.country_id')->orderBy('city_name', 'asc');
}
return Datatables::of($cities)
->filterColumn('state_name', 'whereRaw', '1=1', [])
->filterColumn('country_name', 'whereRaw', '1=1', [])
->addColumn('actions',function($city){
$html = '<a href="'.route('edit_city', $city->id).'" class="btn btn-primary"><i class="fa fa-edit"></i> </a>';
$html .= '<a href="javascript:;" data-id="'.$city->id.'" class="btn btn-danger deleteCity"><i class="fa fa-trash"></i> </a>';
return $html;
})
->removeColumn('id', 'state_id','country_id')->make(true);
}
Hopefully, your issue will be solved
Best Regards