Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
store-locator
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ajay Barthwal
store-locator
Commits
996bb8bc
Commit
996bb8bc
authored
Jul 19, 2019
by
Arpit Jain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Worked on city state drop down and also implemented API according to this drop down
parent
eb5fcc0f
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
153 additions
and
33 deletions
+153
-33
City.php
application/app/City.php
+2
-2
CronController.php
application/app/Http/Controllers/CronController.php
+44
-8
SearchController.php
application/app/Http/Controllers/SearchController.php
+36
-7
Apitraits.php
application/app/Traits/Apitraits.php
+9
-1
city_dropdown.blade.php
application/resources/views/frontend/searchs/city_dropdown.blade.php
+10
-0
index.blade.php
application/resources/views/frontend/searchs/index.blade.php
+44
-14
web.php
application/routes/web.php
+3
-1
updatedquery.php
application/updatedquery.php
+5
-0
No files found.
application/app/City.php
View file @
996bb8bc
...
...
@@ -15,7 +15,7 @@ class City extends Model
public
$sortable
=
[
'id'
,
'name'
,
'
stat
e'
,
'
typ
e'
,
'created_at'
,
'updated_at'
];
...
...
@@ -25,7 +25,7 @@ class City extends Model
* @var array
*/
protected
$fillable
=
[
'name'
,
'
stat
e'
'name'
,
'
typ
e'
];
}
application/app/Http/Controllers/CronController.php
View file @
996bb8bc
...
...
@@ -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
application/app/Http/Controllers/SearchController.php
View file @
996bb8bc
...
...
@@ -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
]);
}
...
...
@@ -184,5 +189,29 @@ 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
]);
}
}
}
application/app/Traits/Apitraits.php
View file @
996bb8bc
...
...
@@ -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
);
...
...
application/resources/views/frontend/searchs/city_dropdown.blade.php
0 → 100644
View file @
996bb8bc
<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
application/resources/views/frontend/searchs/index.blade.php
View file @
996bb8bc
...
...
@@ -16,17 +16,18 @@
<div class="
or
">OR</div>
<div class="
select
">
<select class="
form
-
control
">
<option>State</option>
</select>
</div>
<div class="
select
">
<select class="
form
-
control
">
<option>City</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 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>
...
...
application/routes/web.php
View file @
996bb8bc
...
...
@@ -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
();
...
...
application/updatedquery.php
0 → 100644
View file @
996bb8bc
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment