Commit 0c5513f4 by Ajay Barthwal

Merge branch 'develop' into 'master'

Worked on city state drop down and also implemented API according to this drop down

See merge request !1
parents eb5fcc0f 996bb8bc
......@@ -15,7 +15,7 @@ class City extends Model
public $sortable = ['id',
'name',
'state',
'type',
'created_at',
'updated_at'];
......@@ -25,7 +25,7 @@ class City extends Model
* @var array
*/
protected $fillable = [
'name', 'state'
'name', 'type'
];
}
......@@ -8,7 +8,7 @@ use Validator;
use App\Traits\Apitraits;
use App\Locater;
use App\Page;
//use App\City;
use App\City;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Storage;
......@@ -58,21 +58,56 @@ class CronController extends Controller
}
/*public function getCity(){
public function getState(){
$file = Storage::disk('public')->exists('city.json');
$body = Storage::get('city.json');
$cityData = json_decode($body, true);
$arrayDetail = array();
foreach($cityData as $data){
$city = new City;
$city->name = $data['name'];
$city->state = $data['state'];
$city->parent_id = $data['state'];
$city->save();
$arrayDetail[]= $data['state'];
}
$stateName = array_unique($arrayDetail);
foreach($stateName as $data){
$state = new City;
$state->name = $data;
$state->parent_id = 1;
$state->type = 2;
$state->save();
}
return response()->json([
'status' => 'success',
'data' => 'Updated Sucessfully'
]);
}
public function getCity(){
$file = Storage::disk('public')->exists('city.json');
$body = Storage::get('city.json');
$cityData = json_decode($body, true);
$getStateData = City::where('cities.name', '!=', '')->where('cities.type', '=', '2')->pluck('name','id')->toarray();
foreach($getStateData as $key=>$state){
foreach($cityData as $city){
if($state == $city['state']){
$cityaa = new City;
$cityaa->name = $city['name'];
$cityaa->parent_id = $key;
$cityaa->type = 3;
$cityaa->save();
}
}
}
return response()->json([
'status' => 'success',
'data' => 'Updated Sucessfully'
]);
}*/
}
}
\ No newline at end of file
......@@ -8,6 +8,7 @@ use App\Helpers\Apihelpers;
use App\Traits\Apitraits;
use App\Locater;
use App\Page;
use App\City;
use DB;
use Validator;
use Illuminate\Support\Facades\Hash;
......@@ -26,11 +27,11 @@ class SearchController extends Controller
}
private function getApiData($locality=null, $page=null){
private function getApiData($locality=null, $state=null, $city=null, $location=null, $page=null){
$api_url = config('app.api_list');
$apiLocaterData = $this->call_api_page($api_url, $locality, $page);
$apiLocaterData = $this->call_api_page($api_url, $locality, $state, $city, $location, $page);
if ( count($apiLocaterData['data']) < 1 )
return response()->json(['status' => 'error', 'data' => 'No data found!']);
......@@ -86,7 +87,9 @@ class SearchController extends Controller
$finalData = $final['data']['finalData'];
$links = $final['data']['links'];
$meta = $final['data']['meta'];
return view('frontend.searchs.index', compact('finalData','links','meta'));
$getState = City::where('parent_id', '=', '1')->where('type', '=', '2')->get()->toarray();
return view('frontend.searchs.index', compact('finalData','links','meta','getState'));
}else{
return response()->json(['status' => 'error', 'data' => 'No data found!']);
......@@ -98,8 +101,7 @@ class SearchController extends Controller
* */
public function searchlocater(Request $request)
{
$detail = $this->getApiData($request['locality'], $request['page']);
$detail = $this->getApiData($request['locality'], $request['state'], $request['city'], $request['location'], $request['page']);
$final = $detail->original;
if($final['status'] == 'success'){
......@@ -109,8 +111,11 @@ class SearchController extends Controller
$meta = $final['data']['meta'];
$locality = $request->locality;
$state = $request->state;
$city = $request->city;
$location = $request->location;
$html = view('frontend.searchs.location_element', compact('finalData', 'links', 'locality', 'meta'))->render();
$html = view('frontend.searchs.location_element', compact('finalData', 'links', 'locality','state','city', 'location', 'meta'))->render();
return response()->json([
'status' => 'success',
'data' => $html
......@@ -118,7 +123,7 @@ class SearchController extends Controller
}else{
$html = view('frontend.searchs.location_element', compact('finalData', 'links', 'locality', 'meta'))->render();
$html = view('frontend.searchs.location_element', compact('finalData', 'links', 'locality','state','city', 'location', 'meta'))->render();
return response()->json(['status' => 'error', 'data' => $html]);
}
......@@ -185,4 +190,28 @@ class SearchController extends Controller
return view('frontend.searchs.review_element', compact('reviewData'));
}
/**
* For render location list after searching
* */
public function getCityValue(Request $request)
{
$getCityData = City::where('cities.name', '!=', '')->where('cities.parent_id', '=', $request->state)->pluck('name','id')->toarray();
if(!empty($getCityData)){
$html = view('frontend.searchs.city_dropdown', compact('getCityData'))->render();
return response()->json([
'status' => 'success',
'data' => $html
]);
}else{
$html = view('frontend.searchs.city_dropdown', compact('getCityData'))->render();
return response()->json(['status' => 'error', 'data' => $html]);
}
}
}
......@@ -102,12 +102,20 @@ Trait Apitraits
}
public function call_api_page($api_url, $locatorID=null, $page=1)
public function call_api_page($api_url, $locatorID=null, $state=null, $city=null, $location=null, $page=1)
{
$apiKey = $this->getAPiKey();
if(!empty($locatorID)){
$locatorID = $locatorID;
}else{
$locatorID = $location;
}
$query_param = array(
'keyword' => $locatorID,
'state' => $state,
'city' => $city,
'page' => empty($page) ? 1 : $page
);
......
<select name="city" class="form-control getCityValue">
<option value="">Select City</option>
@if(!empty($getCityData))
@foreach($getCityData as $key => $option)
<option value="<?php echo $option; ?>"><?php echo $option; ?>
</option>
@endforeach
@endif
</select>
\ No newline at end of file
......@@ -16,17 +16,18 @@
<div class="or">OR</div>
<div class="select">
<select class="form-control">
<option>State</option>
<select name="state" class="form-control getStateValue">
<option value="">Select State</option>
@foreach($getState as $key => $option)
<option state="<?php echo $option['name']; ?>" value="<?php echo $option['id']; ?>"><?php echo $option['name']; ?></option>
@endforeach
</select>
</div>
<div class="select">
<select class="form-control">
<option>City</option>
</select>
<div class="select cityData">
@include('frontend.searchs.city_dropdown')
</div>
<div class="select">
<input type="text" class="form-control" placeholder="Location">
<input type="text" class="form-control location" name="location" placeholder="Location">
</div>
<div class="action">
<input type="button" id="searchbutton" value="Submit" class="btn btn-primary">
......@@ -94,14 +95,17 @@
$(function () {
$('#searchbutton').on('click', function (e) {
var locality = $('.locality').val();
var location = $('.location').val();
var state = $('.getStateValue option:selected').attr('state');
var city = $('.getCityValue').val();
e.preventDefault();
$.ajax({
type: 'post',
url: "{{route('searchlocater')}}",
data: $('form').serialize(),
data: {"_token": "{{ csrf_token() }}", locality:locality, location:location, state:state,city:city},
success: function (datanew) {
/*$( "#searchlocaterid" ).html( datanew );*/
if(datanew.status == 'success') {
$('#searchlocaterid').html(datanew.data);
} else {
......@@ -116,25 +120,51 @@
$("#searchlocaterid").on('click','.pagination li a',function () {
var page = $(this).data('page');
var locality = $('.locality').val();
paginate(page,locality);
var state = $('.getStateValue option:selected').attr('state');
var city = $('.getCityValue').val();
var location = $('.location').val();
paginate(page, locality, state, city, location);
});
function paginate(page,locality){
function paginate(page, locality, state, city, location){
$.ajax({
type: 'post',
url: "{{route('searchlocater')}}",
data: {"_token": "{{ csrf_token() }}",page:page,locality:locality},
data: {"_token": "{{ csrf_token() }}",page:page,locality:locality,state:state,city:city,location:location},
success: function (datanew) {
if(datanew.status == 'success') {
$('#searchlocaterid').html(datanew.data);
} else {
$('#searchlocaterid').html(datanew.data);
}
$(".locality").val(locality);
$('.getStateValue option:selected').attr('state');
$(".getCityValue").val(city);
$('.location').val(location);
}
});
}
$(function () {
$('.getStateValue').on('change', function (e) {
var state = $(this).val();
e.preventDefault();
$.ajax({
type: 'post',
url: "{{route('getCityValue')}}",
data: {"_token": "{{ csrf_token() }}",state:state},
success: function (datanew) {
if(datanew.status == 'success') {
$('.cityData').html(datanew.data);
} else {
$('.cityData').html(datanew.data);
}
}
});
});
});
</script>
......
......@@ -20,10 +20,12 @@ Route::post('searchlocater', 'SearchController@searchlocater')->name('searchloca
Route::get('autocomplete', 'SearchController@autocomplete')->name('autocomplete');
Route::get('detail/{slug}', 'SearchController@detail')->name('detail');
Route::post('reviewpaginate', 'SearchController@reviewpaginate')->name('reviewpaginate');
Route::post('getCityValue', 'SearchController@getCityValue')->name('getCityValue');
/* Cron Routes */
Route::get('cron/getLocaterListData', 'CronController@getLocaterListData')->name('getLocaterListData');
//Route::get('cron/getCity', 'CronController@getCity')->name('getCity');
Route::get('cron/getState', 'CronController@getState')->name('getState');
Route::get('cron/getCity', 'CronController@getCity')->name('getCity');
/** End Cron Routes */
Auth::routes();
......
INSERT INTO `cities` (`id`, `name`, `parent_id`, `type`, `status`, `is_deleted`, `created_at`, `updated_at`) VALUES (NULL, 'India', NULL, '1', '1', '0', NULL, NULL);
RUN on browser : WWW_ROOT./cron/getState
RUN on browser : WWW_ROOT./cron/getCity
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment