|
1
|
|
|
<?php namespace Bantenprov\IkProvinsi\Http\Controllers; |
|
2
|
|
|
|
|
3
|
|
|
/* require */ |
|
4
|
|
|
use App\Http\Controllers\Controller; |
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use Bantenprov\IkProvinsi\Facades\IkProvinsi; |
|
7
|
|
|
|
|
8
|
|
|
/* Models */ |
|
9
|
|
|
use Bantenprov\IkProvinsi\Models\Bantenprov\IkProvinsi\IkProvinsi as IkModel; |
|
10
|
|
|
use Bantenprov\IkProvinsi\Models\Bantenprov\IkProvinsi\Province; |
|
11
|
|
|
use Bantenprov\IkProvinsi\Models\Bantenprov\IkProvinsi\Regency; |
|
12
|
|
|
|
|
13
|
|
|
/* etc */ |
|
14
|
|
|
use Validator; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* The IkProvinsiController class. |
|
18
|
|
|
* |
|
19
|
|
|
* @package Bantenprov\IkProvinsi |
|
20
|
|
|
* @author bantenprov <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class IkProvinsiController extends Controller |
|
23
|
|
|
{ |
|
24
|
|
|
|
|
25
|
|
|
protected $province; |
|
26
|
|
|
|
|
27
|
|
|
protected $regency; |
|
28
|
|
|
|
|
29
|
|
|
protected $ik; |
|
30
|
|
|
|
|
31
|
|
|
public function __construct(Regency $regency, Province $province, IkModel $ik) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->regency = $regency; |
|
34
|
|
|
$this->province = $province; |
|
35
|
|
|
$this->ik = $ik; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function index(Request $request) |
|
39
|
|
|
{ |
|
40
|
|
|
/* todo : return json */ |
|
41
|
|
|
|
|
42
|
|
|
return 'index'; |
|
43
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function create() |
|
47
|
|
|
{ |
|
48
|
|
|
|
|
49
|
|
|
return response()->json([ |
|
50
|
|
|
'provinces' => $this->province->all(), |
|
51
|
|
|
'regencies' => $this->regency->all() |
|
52
|
|
|
]); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function show($id) |
|
56
|
|
|
{ |
|
57
|
|
|
|
|
58
|
|
|
$ik = $this->ik->find($id); |
|
59
|
|
|
|
|
60
|
|
|
return response()->json([ |
|
61
|
|
|
'negara' => $ik->negara, |
|
62
|
|
|
'province' => $ik->getProvince->name, |
|
63
|
|
|
'regencies' => $ik->getRegency->name, |
|
64
|
|
|
'tahun' => $ik->tahun, |
|
65
|
|
|
'data' => $ik->data |
|
66
|
|
|
]); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function store(Request $request) |
|
70
|
|
|
{ |
|
71
|
|
|
|
|
72
|
|
|
$validator = Validator::make($request->all(),[ |
|
73
|
|
|
'negara' => 'required', |
|
74
|
|
|
'province_id' => 'required', |
|
75
|
|
|
'regency_id' => 'required', |
|
76
|
|
|
'kab_kota' => 'required', |
|
77
|
|
|
'tahun' => 'required|integer', |
|
78
|
|
|
'data' => 'required|integer', |
|
79
|
|
|
]); |
|
80
|
|
|
|
|
81
|
|
|
if($validator->fails()) |
|
82
|
|
|
{ |
|
83
|
|
|
return response()->json([ |
|
84
|
|
|
'title' => 'error', |
|
85
|
|
|
'message' => 'add failed', |
|
86
|
|
|
'type' => 'failed', |
|
87
|
|
|
'errors' => $validator->errors() |
|
88
|
|
|
]); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
$check = $this->ik->where('regency_id',$request->regency_id)->where('tahun',$request->tahun)->count(); |
|
92
|
|
|
|
|
93
|
|
|
if($check > 0) |
|
94
|
|
|
{ |
|
95
|
|
|
return response()->json([ |
|
96
|
|
|
'title' => 'error', |
|
97
|
|
|
'message' => 'Data allready exist', |
|
98
|
|
|
'type' => 'failed', |
|
99
|
|
|
]); |
|
100
|
|
|
|
|
101
|
|
|
}else{ |
|
102
|
|
|
$data = $this->ik->create($request->all()); |
|
103
|
|
|
|
|
104
|
|
|
return response()->json([ |
|
105
|
|
|
'type' => 'success', |
|
106
|
|
|
'title' => 'success', |
|
107
|
|
|
'id' => $data->id, |
|
108
|
|
|
'message' => 'Indikator Kemiskinan '. $this->regency->find($request->regency_id)->name .' tahun '. $request->tahun .' successfully created', |
|
109
|
|
|
]); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function update(Request $request, $id) |
|
115
|
|
|
{ |
|
116
|
|
|
/* todo : return json */ |
|
117
|
|
|
return ''; |
|
118
|
|
|
|
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function destroy($id) |
|
122
|
|
|
{ |
|
123
|
|
|
/* todo : return json */ |
|
124
|
|
|
return ''; |
|
125
|
|
|
|
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
|