1
|
|
|
<?php |
2
|
|
|
namespace Bantenprov\WilayahIndonesia\Http\Controllers; |
3
|
|
|
|
4
|
|
|
/* Require */ |
5
|
|
|
use App\Http\Controllers\Controller; |
6
|
|
|
use Illuminate\Http\Request; |
7
|
|
|
|
8
|
|
|
/* Models */ |
9
|
|
|
use Laravolt\Indonesia\Indonesia; |
10
|
|
|
use Laravolt\Indonesia\Models\Province; |
11
|
|
|
use Laravolt\Indonesia\Models\City; |
12
|
|
|
use Laravolt\Indonesia\Models\District; |
13
|
|
|
use Laravolt\Indonesia\Models\Village; |
14
|
|
|
|
15
|
|
|
/* Etc */ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The LocationController class. |
19
|
|
|
* |
20
|
|
|
* @package Bantenprov\WilayahIndonesia |
21
|
|
|
* @author bantenprov <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class LocationController extends Controller |
24
|
|
|
{ |
25
|
|
|
protected $indonesia; |
26
|
|
|
protected $province; |
27
|
|
|
protected $city; |
28
|
|
|
protected $district; |
29
|
|
|
protected $village; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Create a new controller instance. |
33
|
|
|
* |
34
|
|
|
* @return void |
|
|
|
|
35
|
|
|
*/ |
36
|
|
|
public function __construct() |
37
|
|
|
{ |
38
|
|
|
$this->indonesia = new Indonesia; |
39
|
|
|
$this->province = new Province; |
40
|
|
|
$this->city = new City; |
41
|
|
|
$this->district = new District; |
42
|
|
|
$this->village = new Village; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Display a listing of the province resource. |
47
|
|
|
* |
48
|
|
|
* @return \Illuminate\Http\Response |
49
|
|
|
*/ |
50
|
|
View Code Duplication |
public function allProvince() |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
$provinces = $this->indonesia->allProvinces(); |
53
|
|
|
|
54
|
|
|
foreach($provinces as $province){ |
55
|
|
|
array_set($province, 'label', $province->name); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$response['province'] = $provinces; |
|
|
|
|
59
|
|
|
$response['status'] = true; |
60
|
|
|
|
61
|
|
|
return response()->json($response); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Display a listing of the province resource. |
66
|
|
|
* |
67
|
|
|
* @return \Illuminate\Http\Response |
68
|
|
|
*/ |
69
|
|
View Code Duplication |
public function detailProvince($id) |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
$provinces = $this->indonesia->findProvince($id); |
72
|
|
|
|
73
|
|
|
array_set($provinces, 'label', $provinces->name); |
74
|
|
|
|
75
|
|
|
$response['province'] = $provinces; |
|
|
|
|
76
|
|
|
$response['status'] = true; |
77
|
|
|
|
78
|
|
|
return response()->json($response); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Display a listing of the city resource. |
83
|
|
|
* |
84
|
|
|
* @return \Illuminate\Http\Response |
85
|
|
|
*/ |
86
|
|
View Code Duplication |
public function allCity() |
|
|
|
|
87
|
|
|
{ |
88
|
|
|
$cities = $this->indonesia->allCities(); |
89
|
|
|
|
90
|
|
|
foreach($cities as $city){ |
91
|
|
|
array_set($city, 'label', $city->name); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$response['city'] = $cities; |
|
|
|
|
95
|
|
|
$response['status'] = true; |
96
|
|
|
|
97
|
|
|
return response()->json($response); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Display a listing of the city resource. |
102
|
|
|
* |
103
|
|
|
* @return \Illuminate\Http\Response |
104
|
|
|
*/ |
105
|
|
View Code Duplication |
public function allCityByProvince($id) |
|
|
|
|
106
|
|
|
{ |
107
|
|
|
$cities = $this->indonesia->findProvince($id, ['cities']); |
108
|
|
|
|
109
|
|
|
if (isset($cities->cities)) { |
110
|
|
|
$cities = $cities->cities; |
111
|
|
|
} else { |
112
|
|
|
$cities = $this->city->getAttributes(); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
foreach($cities as $city){ |
116
|
|
|
array_set($city, 'label', $city->name); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
$response['city'] = $cities; |
|
|
|
|
120
|
|
|
$response['status'] = true; |
121
|
|
|
|
122
|
|
|
return response()->json($response); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Display a listing of the city resource. |
127
|
|
|
* |
128
|
|
|
* @return \Illuminate\Http\Response |
129
|
|
|
*/ |
130
|
|
View Code Duplication |
public function detailCity($id) |
|
|
|
|
131
|
|
|
{ |
132
|
|
|
$cities = $this->indonesia->findCity($id); |
133
|
|
|
|
134
|
|
|
array_set($cities, 'label', $cities->name); |
135
|
|
|
|
136
|
|
|
$response['city'] = $cities; |
|
|
|
|
137
|
|
|
$response['status'] = true; |
138
|
|
|
|
139
|
|
|
return response()->json($response); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Display a listing of the district resource. |
144
|
|
|
* |
145
|
|
|
* @return \Illuminate\Http\Response |
146
|
|
|
*/ |
147
|
|
View Code Duplication |
public function allDistrict() |
|
|
|
|
148
|
|
|
{ |
149
|
|
|
$districts = $this->indonesia->allDistricts(); |
150
|
|
|
|
151
|
|
|
foreach($districts as $district){ |
152
|
|
|
array_set($district, 'label', $district->name); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
$response['district'] = $districts; |
|
|
|
|
156
|
|
|
$response['status'] = true; |
157
|
|
|
|
158
|
|
|
return response()->json($response); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Display a listing of the district resource. |
163
|
|
|
* |
164
|
|
|
* @return \Illuminate\Http\Response |
165
|
|
|
*/ |
166
|
|
View Code Duplication |
public function allDistrictByCity($id) |
|
|
|
|
167
|
|
|
{ |
168
|
|
|
$districts = $this->indonesia->findCity($id, ['districts']); |
169
|
|
|
|
170
|
|
|
if (isset($districts->districts)) { |
171
|
|
|
$districts = $districts->districts; |
172
|
|
|
} else { |
173
|
|
|
$districts = $this->district->getAttributes(); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
foreach($districts as $district){ |
177
|
|
|
array_set($district, 'label', $district->name); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
$response['district'] = $districts; |
|
|
|
|
181
|
|
|
$response['status'] = true; |
182
|
|
|
|
183
|
|
|
return response()->json($response); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Display a listing of the district resource. |
188
|
|
|
* |
189
|
|
|
* @return \Illuminate\Http\Response |
190
|
|
|
*/ |
191
|
|
View Code Duplication |
public function detailDistrict($id) |
|
|
|
|
192
|
|
|
{ |
193
|
|
|
$districts = $this->indonesia->findDistrict($id); |
194
|
|
|
|
195
|
|
|
array_set($districts, 'label', $districts->name); |
196
|
|
|
|
197
|
|
|
$response['district'] = $districts; |
|
|
|
|
198
|
|
|
$response['status'] = true; |
199
|
|
|
|
200
|
|
|
return response()->json($response); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Display a listing of the village resource. |
205
|
|
|
* |
206
|
|
|
* @return \Illuminate\Http\Response |
207
|
|
|
*/ |
208
|
|
View Code Duplication |
public function allVillage() |
|
|
|
|
209
|
|
|
{ |
210
|
|
|
$villages = $this->indonesia->allVillages(); |
211
|
|
|
|
212
|
|
|
foreach($villages as $village){ |
213
|
|
|
array_set($village, 'label', $village->name); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
$response['village'] = $villages; |
|
|
|
|
217
|
|
|
$response['status'] = true; |
218
|
|
|
|
219
|
|
|
return response()->json($response); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Display a listing of the village resource. |
224
|
|
|
* |
225
|
|
|
* @return \Illuminate\Http\Response |
226
|
|
|
*/ |
227
|
|
View Code Duplication |
public function allVillageByDistrict($id) |
|
|
|
|
228
|
|
|
{ |
229
|
|
|
$villages = $this->indonesia->findDistrict($id, ['villages']); |
230
|
|
|
|
231
|
|
|
if (isset($villages->villages)) { |
232
|
|
|
$villages = $villages->villages; |
233
|
|
|
} else { |
234
|
|
|
$villages = $this->village->getAttributes(); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
foreach($villages as $village){ |
238
|
|
|
array_set($village, 'label', $village->name); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
$response['village'] = $villages; |
|
|
|
|
242
|
|
|
$response['status'] = true; |
243
|
|
|
|
244
|
|
|
return response()->json($response); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* Display a listing of the village resource. |
249
|
|
|
* |
250
|
|
|
* @return \Illuminate\Http\Response |
251
|
|
|
*/ |
252
|
|
View Code Duplication |
public function detailVillage($id) |
|
|
|
|
253
|
|
|
{ |
254
|
|
|
$villages = $this->indonesia->findVillage($id); |
255
|
|
|
|
256
|
|
|
array_set($villages, 'label', $villages->name); |
257
|
|
|
|
258
|
|
|
$response['village'] = $villages; |
|
|
|
|
259
|
|
|
$response['status'] = true; |
260
|
|
|
|
261
|
|
|
return response()->json($response); |
262
|
|
|
} |
263
|
|
|
} |
264
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.