|
1
|
|
|
<?php |
|
2
|
|
|
namespace Bantenprov\WilayahIndonesia\Http\Controllers; |
|
3
|
|
|
|
|
4
|
|
|
/* Require */ |
|
5
|
|
|
use App\Http\Controllers\Controller; |
|
6
|
|
|
use Illuminate\Http\Request; |
|
7
|
|
|
use Illuminate\Support\Facades\DB; |
|
8
|
|
|
use Bantenprov\WilayahIndonesia\Facades\WilayahIndonesiaFacade; |
|
9
|
|
|
|
|
10
|
|
|
/* Models */ |
|
11
|
|
|
use Laravolt\Indonesia\Indonesia; |
|
12
|
|
|
use Laravolt\Indonesia\Models\Province; |
|
13
|
|
|
use Laravolt\Indonesia\Models\City; |
|
14
|
|
|
use Laravolt\Indonesia\Models\District; |
|
15
|
|
|
use Laravolt\Indonesia\Models\Village; |
|
16
|
|
|
|
|
17
|
|
|
/* Etc */ |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* The ProvinceController class. |
|
21
|
|
|
* |
|
22
|
|
|
* @package Bantenprov\WilayahIndonesia |
|
23
|
|
|
* @author bantenprov <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
class ProvinceController extends Controller |
|
26
|
|
|
{ |
|
27
|
|
|
protected $indonesia; |
|
28
|
|
|
protected $province; |
|
29
|
|
|
protected $city; |
|
30
|
|
|
protected $district; |
|
31
|
|
|
protected $village; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Create a new controller instance. |
|
35
|
|
|
* |
|
36
|
|
|
* @return void |
|
|
|
|
|
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->indonesia = new Indonesia; |
|
41
|
|
|
$this->province = new Province; |
|
42
|
|
|
$this->city = new City; |
|
43
|
|
|
$this->district = new District; |
|
44
|
|
|
$this->village = new Village; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Display a listing of the resource. |
|
49
|
|
|
* |
|
50
|
|
|
* @return \Illuminate\Http\Response |
|
51
|
|
|
*/ |
|
52
|
|
|
public function get() |
|
53
|
|
|
{ |
|
54
|
|
|
$provinces = $this->indonesia->allProvinces(); |
|
55
|
|
|
|
|
56
|
|
|
foreach ($provinces as $province){ |
|
57
|
|
|
array_set($province, 'label', $province->name); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$response['provinces'] = $provinces; |
|
|
|
|
|
|
61
|
|
|
$response['error'] = false; |
|
62
|
|
|
$response['message'] = 'Loaded'; |
|
63
|
|
|
$response['status'] = true; |
|
64
|
|
|
|
|
65
|
|
|
return response()->json($response); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Display the specified resource. |
|
70
|
|
|
* |
|
71
|
|
|
* @param \App\Province $province |
|
|
|
|
|
|
72
|
|
|
* @return \Illuminate\Http\Response |
|
73
|
|
|
*/ |
|
74
|
|
|
public function show($id) |
|
75
|
|
|
{ |
|
76
|
|
|
$provinces = $this->indonesia->findProvince($id); |
|
77
|
|
|
|
|
78
|
|
|
array_set($provinces, 'label', $provinces->name); |
|
79
|
|
|
|
|
80
|
|
|
$response['provinces'] = $provinces; |
|
|
|
|
|
|
81
|
|
|
$response['error'] = false; |
|
82
|
|
|
$response['message'] = 'Loaded'; |
|
83
|
|
|
$response['status'] = true; |
|
84
|
|
|
|
|
85
|
|
|
return response()->json($response); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
Adding a
@returnannotation 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.