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 ProvinceController class. |
19
|
|
|
* |
20
|
|
|
* @package Bantenprov\WilayahIndonesia |
21
|
|
|
* @author bantenprov <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class ProvinceController 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 resource. |
47
|
|
|
* |
48
|
|
|
* @return \Illuminate\Http\Response |
49
|
|
|
*/ |
50
|
|
|
public function get() |
51
|
|
|
{ |
52
|
|
|
$provinces = $this->indonesia->allProvinces(); |
53
|
|
|
|
54
|
|
|
foreach($provinces as $province){ |
55
|
|
|
array_set($province, 'label', $province->name); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$response['provinces'] = $provinces; |
|
|
|
|
59
|
|
|
$response['message'] = 'Success'; |
60
|
|
|
$response['error'] = false; |
61
|
|
|
$response['status'] = true; |
62
|
|
|
|
63
|
|
|
return response()->json($response); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Display the specified resource. |
68
|
|
|
* |
69
|
|
|
* @param \App\Province $province |
|
|
|
|
70
|
|
|
* @return \Illuminate\Http\Response |
71
|
|
|
*/ |
72
|
|
|
public function show($id) |
73
|
|
|
{ |
74
|
|
|
$provinces = $this->indonesia->findProvince($id); |
75
|
|
|
|
76
|
|
|
array_set($provinces, 'label', $provinces->name); |
77
|
|
|
|
78
|
|
|
$response['provinces'] = $provinces; |
|
|
|
|
79
|
|
|
$response['message'] = 'Success'; |
80
|
|
|
$response['error'] = false; |
81
|
|
|
$response['status'] = true; |
82
|
|
|
|
83
|
|
|
return response()->json($response); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
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.