bantenprov /
wilayah-indonesia
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php namespace Bantenprov\WilayahIndonesia\Http\Controllers; |
||
| 2 | |||
| 3 | use App\Http\Controllers\Controller; |
||
| 4 | use Illuminate\Http\Request; |
||
| 5 | use Bantenprov\WilayahIndonesia\Facades\WilayahIndonesia; |
||
| 6 | use Bantenprov\WilayahIndonesia\Models\Provinsi; |
||
| 7 | use Bantenprov\WilayahIndonesia\Models\Kabupaten; |
||
| 8 | use Bantenprov\WilayahIndonesia\Models\Kecamatan; |
||
| 9 | use Bantenprov\WilayahIndonesia\Models\Desa; |
||
| 10 | use Laravolt\Indonesia\Indonesia; |
||
| 11 | use Illuminate\Support\Facades\Input; |
||
| 12 | use Response; |
||
| 13 | /** |
||
| 14 | * The WilayahIndonesiaController class. |
||
| 15 | * |
||
| 16 | * @package Bantenprov\WilayahIndonesia |
||
| 17 | * @author bantenprov <[email protected]> |
||
| 18 | */ |
||
| 19 | class WilayahIndonesiaController extends Controller |
||
| 20 | { |
||
| 21 | protected $indonesia; |
||
| 22 | protected $provinsi; |
||
| 23 | protected $kabupaten; |
||
| 24 | protected $kecamatan; |
||
| 25 | protected $desa; |
||
| 26 | |||
| 27 | public function __construct() |
||
| 28 | { |
||
| 29 | $this->indonesia = new Indonesia; |
||
| 30 | $this->provinsi = new Provinsi; |
||
| 31 | $this->kabupaten = new Kabupaten; |
||
| 32 | $this->kecamatan = new Kecamatan; |
||
| 33 | $this->desa = new Desa; |
||
| 34 | } |
||
| 35 | public function provinsiindex() |
||
| 36 | { |
||
| 37 | $page = 10; |
||
| 38 | $data = $this->indonesia->paginateProvinces($page); |
||
| 39 | return Response::make(json_encode($data, JSON_PRETTY_PRINT))->header('Content-Type', "application/json"); |
||
| 40 | } |
||
| 41 | public function provinsioption() |
||
| 42 | { |
||
| 43 | $data = $this->provinsi->get(); |
||
| 44 | return Response::make(json_encode($data, JSON_PRETTY_PRINT))->header('Content-Type', "application/json"); |
||
| 45 | } |
||
| 46 | public function provinsicreate() |
||
| 47 | { |
||
| 48 | $provinsi = $this->provinsi; |
||
| 49 | $provinsi->id = Input::get('id'); |
||
| 50 | $provinsi->name = Input::get('name'); |
||
| 51 | $result = $provinsi->save(); |
||
| 52 | if($result){ |
||
| 53 | $res['message'] = 'Success'; |
||
|
0 ignored issues
–
show
|
|||
| 54 | }else{ |
||
| 55 | $res['message'] = 'Error'; |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$res was never initialized. Although not strictly required by PHP, it is generally a good practice to add $res = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. Loading history...
|
|||
| 56 | } |
||
| 57 | return json_encode($res); |
||
| 58 | } |
||
| 59 | public function provinsishow($id) |
||
| 60 | { |
||
| 61 | $data = $this->provinsi->find($id); |
||
| 62 | return json_encode($data); |
||
| 63 | } |
||
| 64 | View Code Duplication | public function provinsiedit($id) |
|
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 65 | { |
||
| 66 | $data = $this->provinsi->find($id); |
||
| 67 | $data->id = Input::get('id'); |
||
| 68 | $data->name = Input::get('name'); |
||
| 69 | $result = $data->save(); |
||
| 70 | if($result){ |
||
| 71 | $res['message'] = 'Success'; |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$res was never initialized. Although not strictly required by PHP, it is generally a good practice to add $res = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. Loading history...
|
|||
| 72 | }else{ |
||
| 73 | $res['message'] = 'Fail'; |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$res was never initialized. Although not strictly required by PHP, it is generally a good practice to add $res = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. Loading history...
|
|||
| 74 | } |
||
| 75 | return json_encode($res); |
||
| 76 | } |
||
| 77 | public function provinsidelete() |
||
| 78 | { |
||
| 79 | $id = Input::get('id'); |
||
| 80 | $provinsi = $this->provinsi; |
||
| 81 | $data = $provinsi->find($id); |
||
| 82 | $result = $data->delete(); |
||
| 83 | if($result){ |
||
| 84 | $res['message'] = 'Success'; |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$res was never initialized. Although not strictly required by PHP, it is generally a good practice to add $res = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. Loading history...
|
|||
| 85 | }else{ |
||
| 86 | $res['message'] = 'Error'; |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$res was never initialized. Although not strictly required by PHP, it is generally a good practice to add $res = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. Loading history...
|
|||
| 87 | } |
||
| 88 | return json_encode($res); |
||
| 89 | } |
||
| 90 | public function provinsisearch($provinsi) |
||
| 91 | { |
||
| 92 | $page = 10; |
||
| 93 | if($provinsi == 'provinsi'){ |
||
| 94 | $data = $this->indonesia->paginateProvinces($page); |
||
| 95 | }elseif($provinsi == 'kabupaten'){ |
||
| 96 | $data = $this->provinsi |
||
| 97 | ->select( |
||
| 98 | 'indonesia_provinces.id as province_id', |
||
| 99 | 'indonesia_provinces.name as province_name', |
||
| 100 | 'indonesia_cities.id as city_id', |
||
| 101 | 'indonesia_cities.name as city_name' |
||
| 102 | ) |
||
| 103 | ->join( |
||
| 104 | 'indonesia_cities', |
||
| 105 | 'indonesia_provinces.id','=','indonesia_cities.province_id' |
||
| 106 | ) |
||
| 107 | ->paginate($page); |
||
| 108 | }elseif($provinsi == 'kecamatan'){ |
||
| 109 | $data = $this->provinsi |
||
| 110 | ->select( |
||
| 111 | 'indonesia_provinces.id as province_id', |
||
| 112 | 'indonesia_provinces.name as province_name', |
||
| 113 | 'indonesia_cities.id as city_id', |
||
| 114 | 'indonesia_cities.name as city_name', |
||
| 115 | 'indonesia_districts.id as district_id', |
||
| 116 | 'indonesia_districts.name as district_name' |
||
| 117 | ) |
||
| 118 | ->join( |
||
| 119 | 'indonesia_cities', |
||
| 120 | 'indonesia_provinces.id','=','indonesia_cities.province_id' |
||
| 121 | ) |
||
| 122 | ->join( |
||
| 123 | 'indonesia_districts', |
||
| 124 | 'indonesia_cities.id','=','indonesia_districts.city_id' |
||
| 125 | ) |
||
| 126 | ->paginate($page); |
||
| 127 | View Code Duplication | }elseif($provinsi == 'desa'){ |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 128 | $data = $this->provinsi |
||
| 129 | ->select( |
||
| 130 | 'indonesia_provinces.id as province_id', |
||
| 131 | 'indonesia_provinces.name as province_name', |
||
| 132 | 'indonesia_cities.id as city_id', |
||
| 133 | 'indonesia_cities.name as city_name', |
||
| 134 | 'indonesia_districts.id as district_id', |
||
| 135 | 'indonesia_districts.name as district_name', |
||
| 136 | 'indonesia_villages.id as village_id', |
||
| 137 | 'indonesia_villages.name as village_name' |
||
| 138 | ) |
||
| 139 | ->join( |
||
| 140 | 'indonesia_cities', |
||
| 141 | 'indonesia_provinces.id','=','indonesia_cities.province_id' |
||
| 142 | ) |
||
| 143 | ->join( |
||
| 144 | 'indonesia_districts', |
||
| 145 | 'indonesia_cities.id','=','indonesia_districts.city_id' |
||
| 146 | ) |
||
| 147 | ->join( |
||
| 148 | 'indonesia_villages', |
||
| 149 | 'indonesia_districts.id','=','indonesia_villages.district_id' |
||
| 150 | ) |
||
| 151 | ->paginate($page); |
||
| 152 | }else{ |
||
| 153 | $string = array('%20','+','-'); |
||
| 154 | foreach($string as $val){ |
||
| 155 | $provinsi = strtoupper(str_replace($val,' ',$provinsi)); |
||
| 156 | } |
||
| 157 | $prov = $this->provinsi->where("name","=","$provinsi")->get(); |
||
| 158 | if($prov->count() > 0){ |
||
| 159 | $provinsi = $prov[0]->id; |
||
| 160 | $data = $this->provinsi |
||
| 161 | ->select( |
||
| 162 | 'indonesia_provinces.id as province_id', |
||
| 163 | 'indonesia_provinces.name as province_name', |
||
| 164 | 'indonesia_cities.id as city_id', |
||
| 165 | 'indonesia_cities.name as city_name' |
||
| 166 | ) |
||
| 167 | ->join( |
||
| 168 | 'indonesia_cities', |
||
| 169 | 'indonesia_provinces.id','=','indonesia_cities.province_id' |
||
| 170 | ) |
||
| 171 | ->where('indonesia_cities.province_id','=',$provinsi) |
||
| 172 | ->paginate($page); |
||
| 173 | }else{ |
||
| 174 | $data = $this->indonesia->paginateProvinces($page); |
||
| 175 | } |
||
| 176 | } |
||
| 177 | return Response::make(json_encode($data, JSON_PRETTY_PRINT))->header('Content-Type', "application/json"); |
||
| 178 | } |
||
| 179 | //END DATA PROVINSI |
||
| 180 | |||
| 181 | //DATA KABUPATEN |
||
| 182 | public function kabupatenindex() |
||
| 183 | { |
||
| 184 | $page = 10; |
||
| 185 | $data = $this->provinsi |
||
| 186 | ->select( |
||
| 187 | 'indonesia_indonesia_provinces.id as province_id', |
||
| 188 | 'indonesia_indonesia_provinces.name as province_name', |
||
| 189 | 'indonesia_cities.id as city_id', |
||
| 190 | 'indonesia_cities.name as city_name' |
||
| 191 | ) |
||
| 192 | ->join( |
||
| 193 | 'indonesia_cities', |
||
| 194 | 'indonesia_provinces.id','=','indonesia_cities.province_id' |
||
| 195 | ) |
||
| 196 | ->paginate($page); |
||
| 197 | return Response::make(json_encode($data, JSON_PRETTY_PRINT))->header('Content-Type', "application/json"); |
||
| 198 | } |
||
| 199 | View Code Duplication | public function kabupatencreate() |
|
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 200 | { |
||
| 201 | $data = $this->kabupaten; |
||
| 202 | $data->province_id = Input::get('province_id'); |
||
| 203 | $data->id = Input::get('city_id'); |
||
| 204 | $data->name = Input::get('city_name'); |
||
| 205 | $result = $data->save(); |
||
| 206 | if($result){ |
||
| 207 | $res['message'] = 'Success'; |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$res was never initialized. Although not strictly required by PHP, it is generally a good practice to add $res = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. Loading history...
|
|||
| 208 | }else{ |
||
| 209 | $res['message'] = 'Error'; |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$res was never initialized. Although not strictly required by PHP, it is generally a good practice to add $res = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. Loading history...
|
|||
| 210 | } |
||
| 211 | return json_encode($res); |
||
| 212 | } |
||
| 213 | public function kabupatenshow($id) |
||
| 214 | { |
||
| 215 | $data = $this->provinsi |
||
| 216 | ->select( |
||
| 217 | 'indonesia_provinces.id as province_id', |
||
| 218 | 'indonesia_provinces.name as province_name', |
||
| 219 | 'indonesia_cities.id as city_id', |
||
| 220 | 'indonesia_cities.name as city_name' |
||
| 221 | ) |
||
| 222 | ->join( |
||
| 223 | 'indonesia_cities', |
||
| 224 | 'indonesia_provinces.id','=','indonesia_cities.province_id' |
||
| 225 | ) |
||
| 226 | ->where('indonesia_cities.id','=',$id) |
||
| 227 | ->first(); |
||
| 228 | return json_encode($data); |
||
| 229 | } |
||
| 230 | View Code Duplication | public function kabupatenedit($id) |
|
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 231 | { |
||
| 232 | $data = $this->kabupaten->find($id); |
||
| 233 | $data->province_id = Input::get('province_id'); |
||
| 234 | $data->id = Input::get('city_id'); |
||
| 235 | $data->name = Input::get('city_name'); |
||
| 236 | $result = $data->save(); |
||
| 237 | if($result){ |
||
| 238 | $res['message'] = 'Success'; |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$res was never initialized. Although not strictly required by PHP, it is generally a good practice to add $res = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. Loading history...
|
|||
| 239 | }else{ |
||
| 240 | $res['message'] = 'Error'; |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$res was never initialized. Although not strictly required by PHP, it is generally a good practice to add $res = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. Loading history...
|
|||
| 241 | } |
||
| 242 | return json_encode($res); |
||
| 243 | } |
||
| 244 | public function kabupatendelete() |
||
| 245 | { |
||
| 246 | $id = Input::get('city_id'); |
||
| 247 | $kabupaten = $this->kabupaten; |
||
| 248 | $data = $kabupaten->find($id); |
||
| 249 | $result = $data->delete(); |
||
| 250 | if($result){ |
||
| 251 | $res['message'] = 'Success'; |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$res was never initialized. Although not strictly required by PHP, it is generally a good practice to add $res = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. Loading history...
|
|||
| 252 | }else{ |
||
| 253 | $res['message'] = 'Error'; |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$res was never initialized. Although not strictly required by PHP, it is generally a good practice to add $res = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. Loading history...
|
|||
| 254 | } |
||
| 255 | return json_encode($res); |
||
| 256 | } |
||
| 257 | public function kabupatensearch($provinsi,$kabupaten) |
||
| 258 | { |
||
| 259 | $page = 10; |
||
| 260 | if($provinsi == 'provinsi'){ |
||
| 261 | $data = $this->indonesia->paginateProvinces($page); |
||
| 262 | }elseif($provinsi == 'kabupaten'){ |
||
| 263 | $data = $this->provinsi |
||
| 264 | ->select( |
||
| 265 | 'indonesia_provinces.id as province_id', |
||
| 266 | 'indonesia_provinces.name as province_name', |
||
| 267 | 'indonesia_cities.id as city_id', |
||
| 268 | 'indonesia_cities.name as city_name' |
||
| 269 | ) |
||
| 270 | ->join( |
||
| 271 | 'indonesia_cities', |
||
| 272 | 'indonesia_provinces.id','=','indonesia_cities.province_id' |
||
| 273 | ) |
||
| 274 | ->paginate($page); |
||
| 275 | }elseif($provinsi == 'kecamatan'){ |
||
| 276 | $data = $this->provinsi |
||
| 277 | ->select( |
||
| 278 | 'indonesia_provinces.id as province_id', |
||
| 279 | 'indonesia_provinces.name as province_name', |
||
| 280 | 'indonesia_cities.id as city_id', |
||
| 281 | 'indonesia_cities.name as city_name', |
||
| 282 | 'indonesia_districts.id as district_id', |
||
| 283 | 'indonesia_districts.name as district_name' |
||
| 284 | ) |
||
| 285 | ->join( |
||
| 286 | 'indonesia_cities', |
||
| 287 | 'indonesia_provinces.id','=','indonesia_cities.province_id' |
||
| 288 | ) |
||
| 289 | ->join( |
||
| 290 | 'indonesia_districts', |
||
| 291 | 'indonesia_cities.id','=','indonesia_districts.city_id' |
||
| 292 | ) |
||
| 293 | ->paginate($page); |
||
| 294 | View Code Duplication | }elseif($provinsi == 'desa'){ |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 295 | $data = $this->provinsi |
||
| 296 | ->select( |
||
| 297 | 'indonesia_provinces.id as province_id', |
||
| 298 | 'indonesia_provinces.name as province_name', |
||
| 299 | 'indonesia_cities.id as city_id', |
||
| 300 | 'indonesia_cities.name as city_name', |
||
| 301 | 'indonesia_districts.id as district_id', |
||
| 302 | 'indonesia_districts.name as district_name', |
||
| 303 | 'indonesia_villages.id as village_id', |
||
| 304 | 'indonesia_villages.name as village_name' |
||
| 305 | ) |
||
| 306 | ->join( |
||
| 307 | 'indonesia_cities', |
||
| 308 | 'indonesia_provinces.id','=','indonesia_cities.province_id' |
||
| 309 | ) |
||
| 310 | ->join( |
||
| 311 | 'indonesia_districts', |
||
| 312 | 'indonesia_cities.id','=','indonesia_districts.city_id' |
||
| 313 | ) |
||
| 314 | ->join( |
||
| 315 | 'indonesia_villages', |
||
| 316 | 'indonesia_districts.id','=','indonesia_villages.district_id' |
||
| 317 | ) |
||
| 318 | ->paginate($page); |
||
| 319 | }else{ |
||
| 320 | $string = array('%20','+','-'); |
||
| 321 | foreach($string as $val){ |
||
| 322 | $provinsi = strtoupper(str_replace($val,' ',$provinsi)); |
||
| 323 | } |
||
| 324 | $prov = $this->provinsi->where("name","=","$provinsi")->get(); |
||
| 325 | if($prov->count() > 0){ |
||
| 326 | $provinsi = $prov[0]->id; |
||
| 327 | foreach($string as $val){ |
||
| 328 | $kabupaten = strtoupper(str_replace($val,' ',$kabupaten)); |
||
| 329 | } |
||
| 330 | $kab = $this->kabupaten->where("province_id","=","$provinsi")->where("name","=","$kabupaten")->get(); |
||
| 331 | if($kab->count() == 0){ |
||
| 332 | $kabupaten = 'KABUPATEN '.$kabupaten; |
||
| 333 | } |
||
| 334 | $kab1 = $this->kabupaten->where("province_id","=","$provinsi")->where("name","=","$kabupaten")->get(); |
||
| 335 | if($kab1->count() == 0){ |
||
| 336 | $kabupaten = 'KAB '.$kabupaten; |
||
| 337 | } |
||
| 338 | $kab2 = $this->kabupaten->where("province_id","=","$provinsi")->where("name","=","$kabupaten")->get(); |
||
| 339 | if($kab2->count() == 0){ |
||
| 340 | $kabupaten = 'KAB. '.$kabupaten; |
||
| 341 | } |
||
| 342 | $kab3 = $this->kabupaten->where("province_id","=","$provinsi")->where("name","=","$kabupaten")->get(); |
||
| 343 | if(($kab->count() > 0) || ($kab1->count() > 0) || ($kab2->count() > 0) || ($kab3->count() > 0)){ |
||
| 344 | View Code Duplication | if(isset($kab[0]->id)){ |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 345 | $kabupaten = $kab[0]->id; |
||
| 346 | }elseif(isset($kab1[0]->id)){ |
||
| 347 | $kabupaten = $kab1[0]->id; |
||
| 348 | }elseif(isset($kab2[0]->id)){ |
||
| 349 | $kabupaten = $kab2[0]->id; |
||
| 350 | }elseif(isset($kab3[0]->id)){ |
||
| 351 | $kabupaten = $kab3[0]->id; |
||
| 352 | } |
||
| 353 | $data = $this->provinsi |
||
| 354 | ->select( |
||
| 355 | 'indonesia_provinces.id as province_id', |
||
| 356 | 'indonesia_provinces.name as province_name', |
||
| 357 | 'indonesia_cities.id as city_id', |
||
| 358 | 'indonesia_cities.name as city_name', |
||
| 359 | 'indonesia_districts.id as district_id', |
||
| 360 | 'indonesia_districts.name as district_name' |
||
| 361 | ) |
||
| 362 | ->join( |
||
| 363 | 'indonesia_cities', |
||
| 364 | 'indonesia_provinces.id','=','indonesia_cities.province_id' |
||
| 365 | ) |
||
| 366 | ->join( |
||
| 367 | 'indonesia_districts', |
||
| 368 | 'indonesia_cities.id','=','indonesia_districts.city_id' |
||
| 369 | ) |
||
| 370 | ->where('indonesia_districts.city_id','=',$kabupaten) |
||
| 371 | ->paginate($page); |
||
| 372 | }else{ |
||
| 373 | $data = $this->provinsi |
||
| 374 | ->select( |
||
| 375 | 'indonesia_provinces.id as province_id', |
||
| 376 | 'indonesia_provinces.name as province_name', |
||
| 377 | 'indonesia_cities.id as city_id', |
||
| 378 | 'indonesia_cities.name as city_name' |
||
| 379 | ) |
||
| 380 | ->join( |
||
| 381 | 'indonesia_cities', |
||
| 382 | 'indonesia_provinces.id','=','indonesia_cities.province_id' |
||
| 383 | ) |
||
| 384 | ->where('indonesia_cities.province_id','=',$provinsi) |
||
| 385 | ->paginate($page); |
||
| 386 | } |
||
| 387 | }else{ |
||
| 388 | $data = $this->indonesia->paginateProvinces($page); |
||
| 389 | } |
||
| 390 | } |
||
| 391 | return Response::make(json_encode($data, JSON_PRETTY_PRINT))->header('Content-Type', "application/json"); |
||
| 392 | } |
||
| 393 | //END DATA KABUPATEN |
||
| 394 | |||
| 395 | //DATA KECAMATAN |
||
| 396 | public function kecamatanindex() |
||
| 397 | { |
||
| 398 | $page = 10; |
||
| 399 | $data = $this->provinsi |
||
| 400 | ->select( |
||
| 401 | 'indonesia_provinces.id as province_id', |
||
| 402 | 'indonesia_provinces.name as province_name', |
||
| 403 | 'indonesia_cities.id as city_id', |
||
| 404 | 'indonesia_cities.name as city_name', |
||
| 405 | 'indonesia_districts.id as district_id', |
||
| 406 | 'indonesia_districts.name as district_name' |
||
| 407 | ) |
||
| 408 | ->join( |
||
| 409 | 'indonesia_cities', |
||
| 410 | 'indonesia_provinces.id','=','indonesia_cities.province_id' |
||
| 411 | ) |
||
| 412 | ->join( |
||
| 413 | 'indonesia_districts', |
||
| 414 | 'indonesia_cities.id','=','indonesia_districts.city_id' |
||
| 415 | ) |
||
| 416 | ->paginate($page); |
||
| 417 | return Response::make(json_encode($data, JSON_PRETTY_PRINT))->header('Content-Type', "application/json"); |
||
| 418 | } |
||
| 419 | public function kecamatancreate() |
||
| 420 | { |
||
| 421 | |||
| 422 | } |
||
| 423 | public function kecamatanshow() |
||
| 424 | { |
||
| 425 | |||
| 426 | } |
||
| 427 | public function kecamatanedit() |
||
| 428 | { |
||
| 429 | |||
| 430 | } |
||
| 431 | public function kecamatandelete() |
||
| 432 | { |
||
| 433 | |||
| 434 | } |
||
| 435 | public function kecamatansearch($provinsi,$kabupaten,$kecamatan) |
||
| 436 | { |
||
| 437 | $page = 10; |
||
| 438 | if($provinsi == 'provinsi'){ |
||
| 439 | $data = $this->indonesia->paginateProvinces($page); |
||
| 440 | }elseif($provinsi == 'kabupaten'){ |
||
| 441 | $data = $this->provinsi |
||
| 442 | ->select( |
||
| 443 | 'indonesia_provinces.id as province_id', |
||
| 444 | 'indonesia_provinces.name as province_name', |
||
| 445 | 'indonesia_cities.id as city_id', |
||
| 446 | 'indonesia_cities.name as city_name' |
||
| 447 | ) |
||
| 448 | ->join( |
||
| 449 | 'indonesia_cities', |
||
| 450 | 'indonesia_provinces.id','=','indonesia_cities.province_id' |
||
| 451 | ) |
||
| 452 | ->paginate($page); |
||
| 453 | }elseif($provinsi == 'kecamatan'){ |
||
| 454 | $data = $this->provinsi |
||
| 455 | ->select( |
||
| 456 | 'indonesia_provinces.id as province_id', |
||
| 457 | 'indonesia_provinces.name as province_name', |
||
| 458 | 'indonesia_cities.id as city_id', |
||
| 459 | 'indonesia_cities.name as city_name', |
||
| 460 | 'indonesia_districts.id as district_id', |
||
| 461 | 'indonesia_districts.name as district_name' |
||
| 462 | ) |
||
| 463 | ->join( |
||
| 464 | 'indonesia_cities', |
||
| 465 | 'indonesia_provinces.id','=','indonesia_cities.province_id' |
||
| 466 | ) |
||
| 467 | ->join( |
||
| 468 | 'indonesia_districts', |
||
| 469 | 'indonesia_cities.id','=','indonesia_districts.city_id' |
||
| 470 | ) |
||
| 471 | ->paginate($page); |
||
| 472 | View Code Duplication | }elseif($provinsi == 'desa'){ |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 473 | $data = $this->provinsi |
||
| 474 | ->select( |
||
| 475 | 'indonesia_provinces.id as province_id', |
||
| 476 | 'indonesia_provinces.name as province_name', |
||
| 477 | 'indonesia_cities.id as city_id', |
||
| 478 | 'indonesia_cities.name as city_name', |
||
| 479 | 'indonesia_districts.id as district_id', |
||
| 480 | 'indonesia_districts.name as district_name', |
||
| 481 | 'indonesia_villages.id as village_id', |
||
| 482 | 'indonesia_villages.name as village_name' |
||
| 483 | ) |
||
| 484 | ->join( |
||
| 485 | 'indonesia_cities', |
||
| 486 | 'indonesia_provinces.id','=','indonesia_cities.province_id' |
||
| 487 | ) |
||
| 488 | ->join( |
||
| 489 | 'indonesia_districts', |
||
| 490 | 'indonesia_cities.id','=','indonesia_districts.city_id' |
||
| 491 | ) |
||
| 492 | ->join( |
||
| 493 | 'indonesia_villages', |
||
| 494 | 'indonesia_districts.id','=','indonesia_villages.district_id' |
||
| 495 | ) |
||
| 496 | ->paginate($page); |
||
| 497 | }else{ |
||
| 498 | $string = array('%20','+','-'); |
||
| 499 | foreach($string as $val){ |
||
| 500 | $provinsi = strtoupper(str_replace($val,' ',$provinsi)); |
||
| 501 | } |
||
| 502 | $prov = $this->provinsi->where("name","=","$provinsi")->get(); |
||
| 503 | if($prov->count() > 0){ |
||
| 504 | $provinsi = $prov[0]->id; |
||
| 505 | foreach($string as $val){ |
||
| 506 | $kabupaten = strtoupper(str_replace($val,' ',$kabupaten)); |
||
| 507 | } |
||
| 508 | $kab = $this->kabupaten->where("province_id","=","$provinsi")->where("name","=","$kabupaten")->get(); |
||
| 509 | if($kab->count() == 0){ |
||
| 510 | $kabupaten = 'KABUPATEN '.$kabupaten; |
||
| 511 | } |
||
| 512 | $kab1 = $this->kabupaten->where("province_id","=","$provinsi")->where("name","=","$kabupaten")->get(); |
||
| 513 | if($kab1->count() == 0){ |
||
| 514 | $kabupaten = 'KAB '.$kabupaten; |
||
| 515 | } |
||
| 516 | $kab2 = $this->kabupaten->where("province_id","=","$provinsi")->where("name","=","$kabupaten")->get(); |
||
| 517 | if($kab2->count() == 0){ |
||
| 518 | $kabupaten = 'KAB. '.$kabupaten; |
||
| 519 | } |
||
| 520 | $kab3 = $this->kabupaten->where("province_id","=","$provinsi")->where("name","=","$kabupaten")->get(); |
||
| 521 | if(($kab->count() > 0) || ($kab1->count() > 0) || ($kab2->count() > 0) || ($kab3->count() > 0)){ |
||
| 522 | View Code Duplication | if(isset($kab[0]->id)){ |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 523 | $kabupaten = $kab[0]->id; |
||
| 524 | }elseif(isset($kab1[0]->id)){ |
||
| 525 | $kabupaten = $kab1[0]->id; |
||
| 526 | }elseif(isset($kab2[0]->id)){ |
||
| 527 | $kabupaten = $kab2[0]->id; |
||
| 528 | }elseif(isset($kab3[0]->id)){ |
||
| 529 | $kabupaten = $kab3[0]->id; |
||
| 530 | } |
||
| 531 | foreach($string as $val){ |
||
| 532 | $kecamatan = strtoupper(str_replace($val,' ',$kecamatan)); |
||
| 533 | } |
||
| 534 | $kec = $this->kecamatan->where("city_id","=","$kabupaten")->where("name","=","$kecamatan")->get(); |
||
| 535 | if($kec->count() == 0){ |
||
| 536 | $kecamatan = 'KECAMATAN '.$kecamatan; |
||
| 537 | } |
||
| 538 | $kec1 = $this->kecamatan->where("city_id","=","$kabupaten")->where("name","=","$kecamatan")->get(); |
||
| 539 | if($kec1->count() == 0){ |
||
| 540 | $kecamatan = 'KEC '.$kecamatan; |
||
| 541 | } |
||
| 542 | $kec2 = $this->kecamatan->where("city_id","=","$kabupaten")->where("name","=","$kecamatan")->get(); |
||
| 543 | if($kec2->count() == 0){ |
||
| 544 | $kecamatan = 'KEC. '.$kecamatan; |
||
| 545 | } |
||
| 546 | $kec3 = $this->kecamatan->where("city_id","=","$kabupaten")->where("name","=","$kecamatan")->get(); |
||
| 547 | if(($kec->count() > 0) || ($kec1->count() > 0) || ($kec2->count() > 0) || ($kec3->count() > 0)){ |
||
| 548 | View Code Duplication | if(isset($kec[0]->id)){ |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 549 | $kecamatan = $kec[0]->id; |
||
| 550 | }elseif(isset($kec1[0]->id)){ |
||
| 551 | $kecamatan = $kec1[0]->id; |
||
| 552 | }elseif(isset($kec2[0]->id)){ |
||
| 553 | $kecamatan = $kec2[0]->id; |
||
| 554 | }elseif(isset($kec3[0]->id)){ |
||
| 555 | $kecamatan = $kec3[0]->id; |
||
| 556 | } |
||
| 557 | $data = $this->provinsi |
||
| 558 | ->select( |
||
| 559 | 'indonesia_provinces.id as province_id', |
||
| 560 | 'indonesia_provinces.name as province_name', |
||
| 561 | 'indonesia_cities.id as city_id', |
||
| 562 | 'indonesia_cities.name as city_name', |
||
| 563 | 'indonesia_districts.id as district_id', |
||
| 564 | 'indonesia_districts.name as district_name', |
||
| 565 | 'indonesia_villages.id as village_id', |
||
| 566 | 'indonesia_villages.name as village_name' |
||
| 567 | ) |
||
| 568 | ->join( |
||
| 569 | 'indonesia_cities', |
||
| 570 | 'indonesia_provinces.id','=','indonesia_cities.province_id' |
||
| 571 | ) |
||
| 572 | ->join( |
||
| 573 | 'indonesia_districts', |
||
| 574 | 'indonesia_cities.id','=','indonesia_districts.city_id' |
||
| 575 | ) |
||
| 576 | ->join( |
||
| 577 | 'indonesia_villages', |
||
| 578 | 'indonesia_districts.id','=','indonesia_villages.district_id' |
||
| 579 | ) |
||
| 580 | ->where('indonesia_villages.district_id','=',$kecamatan) |
||
| 581 | ->paginate($page); |
||
| 582 | }else{ |
||
| 583 | $data = $this->provinsi |
||
| 584 | ->select( |
||
| 585 | 'indonesia_provinces.id as province_id', |
||
| 586 | 'indonesia_provinces.name as province_name', |
||
| 587 | 'indonesia_cities.id as city_id', |
||
| 588 | 'indonesia_cities.name as city_name', |
||
| 589 | 'indonesia_districts.id as district_id', |
||
| 590 | 'indonesia_districts.name as district_name' |
||
| 591 | ) |
||
| 592 | ->join( |
||
| 593 | 'indonesia_cities', |
||
| 594 | 'indonesia_provinces.id','=','indonesia_cities.province_id' |
||
| 595 | ) |
||
| 596 | ->join( |
||
| 597 | 'indonesia_districts', |
||
| 598 | 'indonesia_cities.id','=','indonesia_districts.city_id' |
||
| 599 | ) |
||
| 600 | ->where('indonesia_districts.city_id','=',$kabupaten) |
||
| 601 | ->paginate($page); |
||
| 602 | } |
||
| 603 | }else{ |
||
| 604 | $data = $this->provinsi |
||
| 605 | ->select( |
||
| 606 | 'indonesia_provinces.id as province_id', |
||
| 607 | 'indonesia_provinces.name as province_name', |
||
| 608 | 'indonesia_cities.id as city_id', |
||
| 609 | 'indonesia_cities.name as city_name' |
||
| 610 | ) |
||
| 611 | ->join( |
||
| 612 | 'indonesia_cities', |
||
| 613 | 'indonesia_provinces.id','=','indonesia_cities.province_id' |
||
| 614 | ) |
||
| 615 | ->where('indonesia_cities.province_id','=',$provinsi) |
||
| 616 | ->paginate($page); |
||
| 617 | } |
||
| 618 | }else{ |
||
| 619 | $data = $this->indonesia->paginateProvinces($page); |
||
| 620 | } |
||
| 621 | } |
||
| 622 | return Response::make(json_encode($data, JSON_PRETTY_PRINT))->header('Content-Type', "application/json"); |
||
| 623 | } |
||
| 624 | //END DATA KECAMATAN |
||
| 625 | |||
| 626 | //DATA DESA |
||
| 627 | public function desaindex() |
||
| 628 | { |
||
| 629 | $page = 10; |
||
| 630 | $data = $this->provinsi |
||
| 631 | ->select( |
||
| 632 | 'indonesia_provinces.id as province_id', |
||
| 633 | 'indonesia_provinces.name as province_name', |
||
| 634 | 'indonesia_cities.id as city_id', |
||
| 635 | 'indonesia_cities.name as city_name', |
||
| 636 | 'indonesia_districts.id as district_id', |
||
| 637 | 'indonesia_districts.name as district_name', |
||
| 638 | 'indonesia_villages.id as village_id', |
||
| 639 | 'indonesia_villages.name as village_name' |
||
| 640 | ) |
||
| 641 | ->join( |
||
| 642 | 'indonesia_cities', |
||
| 643 | 'indonesia_provinces.id','=','indonesia_cities.province_id' |
||
| 644 | ) |
||
| 645 | ->join( |
||
| 646 | 'indonesia_districts', |
||
| 647 | 'indonesia_cities.id','=','indonesia_districts.city_id' |
||
| 648 | ) |
||
| 649 | ->join( |
||
| 650 | 'indonesia_villages', |
||
| 651 | 'indonesia_districts.id','=','indonesia_villages.district_id' |
||
| 652 | ) |
||
| 653 | ->paginate($page); |
||
| 654 | return Response::make(json_encode($data, JSON_PRETTY_PRINT))->header('Content-Type', "application/json"); |
||
| 655 | } |
||
| 656 | public function desacreate() |
||
| 657 | { |
||
| 658 | |||
| 659 | } |
||
| 660 | public function desashow() |
||
| 661 | { |
||
| 662 | |||
| 663 | } |
||
| 664 | public function desaedit() |
||
| 665 | { |
||
| 666 | |||
| 667 | } |
||
| 668 | public function desadelete() |
||
| 669 | { |
||
| 670 | |||
| 671 | } |
||
| 672 | //END DATA DESA |
||
| 673 | |||
| 674 | } |
||
| 675 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.