1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace Bantenprov\DashboardEpormas\Http\Controllers;
|
4
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
6
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
7
|
|
|
use Illuminate\Support\Facades\DB;
|
8
|
|
|
use Illuminate\Support\Facades\Input;
|
9
|
|
|
use Bantenprov\DashboardEpormas\Models\EpormasCity;
|
10
|
|
|
use Validator, Image, Session, File, Response, Redirect, Exception;
|
11
|
|
|
|
12
|
|
|
class EpormasCityController extends Controller
|
13
|
|
|
{
|
14
|
|
|
|
15
|
|
|
/**
|
16
|
|
|
* Display a listing of the resource.
|
17
|
|
|
*
|
18
|
|
|
* @return Response
|
19
|
|
|
*/
|
20
|
|
|
public function index()
|
21
|
|
|
{
|
22
|
|
|
try {
|
23
|
|
|
$error = false;
|
24
|
|
|
$statusCode = 200;
|
25
|
|
|
$title = 'Success';
|
26
|
|
|
$type = 'success';
|
27
|
|
|
$message = 'Success';
|
28
|
|
|
$result = EpormasCity::all();
|
29
|
|
|
} catch (Exception $e) {
|
30
|
|
|
$error = true;
|
31
|
|
|
$statusCode = 404;
|
32
|
|
|
$title = 'Error';
|
33
|
|
|
$type = 'error';
|
34
|
|
|
$message = 'Error';
|
35
|
|
|
$result = 'Not Found';
|
36
|
|
|
} finally {
|
37
|
|
|
return Response::json(array(
|
38
|
|
|
'error' => $error,
|
39
|
|
|
'status' => $statusCode,
|
40
|
|
|
'title' => $title,
|
41
|
|
|
'type' => $type,
|
42
|
|
|
'message' => $message,
|
43
|
|
|
'result' => $result
|
44
|
|
|
));
|
45
|
|
|
}
|
46
|
|
|
}
|
47
|
|
|
|
48
|
|
|
/**
|
49
|
|
|
* Show the form for creating a new resource.
|
50
|
|
|
*
|
51
|
|
|
* @return Response
|
52
|
|
|
*/
|
53
|
|
|
public function create()
|
54
|
|
|
{
|
55
|
|
|
|
56
|
|
|
}
|
57
|
|
|
|
58
|
|
|
/**
|
59
|
|
|
* Store a newly created resource in storage.
|
60
|
|
|
*
|
61
|
|
|
* @return Response
|
62
|
|
|
*/
|
63
|
|
|
public function store(Request $request, $version='')
|
64
|
|
|
{
|
65
|
|
|
$path = \Request::path();
|
66
|
|
|
$explode = explode('/', $path);
|
67
|
|
|
|
68
|
|
|
$from = 'form';
|
69
|
|
|
if(in_array('api',$explode)){
|
70
|
|
|
$from = 'api';
|
71
|
|
|
}
|
72
|
|
|
|
73
|
|
|
$via = $from;
|
74
|
|
|
if($version != '' && $version != 'store'){
|
75
|
|
|
$via .= '-'.$version;
|
76
|
|
|
}
|
77
|
|
|
|
78
|
|
|
$rules = [
|
79
|
|
|
'name' => 'required'
|
80
|
|
|
];
|
81
|
|
|
|
82
|
|
|
$validator = Validator::make($request->all(), $rules);
|
83
|
|
|
if ($validator->fails()) {
|
84
|
|
|
return Response::json(array(
|
85
|
|
|
'title' => 'Error',
|
86
|
|
|
'type' => 'error',
|
87
|
|
|
'message' => $validator->errors()->all()
|
88
|
|
|
));
|
89
|
|
|
}
|
90
|
|
|
|
91
|
|
|
$data = EpormasCity::whereNull('deleted_at')
|
92
|
|
|
->where('name', $request->name)
|
93
|
|
|
->count();
|
94
|
|
|
if($data > 0){
|
95
|
|
|
return Response::json(array(
|
96
|
|
|
'title' => 'Error',
|
97
|
|
|
'type' => 'error',
|
98
|
|
|
'message' => 'Data has already been taken.'
|
99
|
|
|
));
|
100
|
|
|
}
|
101
|
|
|
|
102
|
|
|
$error = false;
|
103
|
|
|
$statusCode = 200;
|
104
|
|
|
$title = 'Success';
|
105
|
|
|
$type = 'success';
|
106
|
|
|
$message = 'Data created successfully';
|
107
|
|
|
$result = EpormasCity::create([
|
108
|
|
|
'name' => $request->name
|
109
|
|
|
]);
|
110
|
|
|
return Response::json(array(
|
111
|
|
|
'error' => $error,
|
112
|
|
|
'status' => $statusCode,
|
113
|
|
|
'title' => $title,
|
114
|
|
|
'type' => $type,
|
115
|
|
|
'message' => $message,
|
116
|
|
|
'result' => $result
|
117
|
|
|
));
|
118
|
|
|
}
|
119
|
|
|
|
120
|
|
|
/**
|
121
|
|
|
* Display the specified resource.
|
122
|
|
|
*
|
123
|
|
|
* @param int $id
|
124
|
|
|
* @return Response
|
125
|
|
|
*/
|
126
|
|
|
public function show($version='', $id)
|
127
|
|
|
{
|
128
|
|
|
try {
|
129
|
|
|
$error = false;
|
130
|
|
|
$statusCode = 200;
|
131
|
|
|
$title = 'Success';
|
132
|
|
|
$type = 'success';
|
133
|
|
|
$message = 'Success';
|
134
|
|
|
$result = EpormasCity::findOrFail($id);
|
135
|
|
|
} catch (Exception $e) {
|
136
|
|
|
$error = true;
|
137
|
|
|
$statusCode = 404;
|
138
|
|
|
$title = 'Error';
|
139
|
|
|
$type = 'error';
|
140
|
|
|
$message = 'Error';
|
141
|
|
|
$result = 'Not Found';
|
142
|
|
|
} finally {
|
143
|
|
|
return Response::json(array(
|
144
|
|
|
'error' => $error,
|
145
|
|
|
'status' => $statusCode,
|
146
|
|
|
'title' => $title,
|
147
|
|
|
'type' => $type,
|
148
|
|
|
'message' => $message,
|
149
|
|
|
'result' => $result
|
150
|
|
|
));
|
151
|
|
|
}
|
152
|
|
|
}
|
153
|
|
|
|
154
|
|
|
/**
|
155
|
|
|
* Show the form for editing the specified resource.
|
156
|
|
|
*
|
157
|
|
|
* @param int $id
|
158
|
|
|
* @return Response
|
159
|
|
|
*/
|
160
|
|
|
public function edit($id)
|
161
|
|
|
{
|
162
|
|
|
try {
|
163
|
|
|
$error = false;
|
164
|
|
|
$statusCode = 200;
|
165
|
|
|
$title = 'Success';
|
166
|
|
|
$type = 'success';
|
167
|
|
|
$message = 'Success';
|
168
|
|
|
$result = EpormasCity::findOrFail($id);
|
169
|
|
|
} catch (Exception $e) {
|
170
|
|
|
$error = true;
|
171
|
|
|
$statusCode = 404;
|
172
|
|
|
$title = 'Error';
|
173
|
|
|
$type = 'error';
|
174
|
|
|
$message = 'Error';
|
175
|
|
|
$result = 'Not Found';
|
176
|
|
|
} finally {
|
177
|
|
|
return Response::json(array(
|
178
|
|
|
'error' => $error,
|
179
|
|
|
'status' => $statusCode,
|
180
|
|
|
'title' => $title,
|
181
|
|
|
'type' => $type,
|
182
|
|
|
'message' => $message,
|
183
|
|
|
'result' => $result
|
184
|
|
|
));
|
185
|
|
|
}
|
186
|
|
|
}
|
187
|
|
|
|
188
|
|
|
/**
|
189
|
|
|
* Update the specified resource in storage.
|
190
|
|
|
*
|
191
|
|
|
* @param int $id
|
192
|
|
|
* @return Response
|
193
|
|
|
*/
|
194
|
|
|
public function update(Request $request, $version='', $id)
|
195
|
|
|
{
|
196
|
|
|
$result = EpormasCity::find($id);
|
197
|
|
|
|
198
|
|
|
$rules = [
|
199
|
|
|
'name' => 'required'
|
200
|
|
|
];
|
201
|
|
|
|
202
|
|
|
$validator = Validator::make($request->all(), $rules);
|
203
|
|
|
if ($validator->fails()) {
|
204
|
|
|
return Response::json(array(
|
205
|
|
|
'title' => 'Error',
|
206
|
|
|
'type' => 'error',
|
207
|
|
|
'message' => $validator->errors()->all()
|
208
|
|
|
));
|
209
|
|
|
}
|
210
|
|
|
|
211
|
|
|
if($request->name != $result->name){
|
212
|
|
|
$data = EpormasCity::whereNull('deleted_at')
|
213
|
|
|
->where('name', $request->name)
|
214
|
|
|
->count();
|
215
|
|
|
if($data > 0){
|
216
|
|
|
return Response::json(array(
|
217
|
|
|
'title' => 'Error',
|
218
|
|
|
'type' => 'error',
|
219
|
|
|
'message' => 'Data has already been taken.'
|
220
|
|
|
));
|
221
|
|
|
}
|
222
|
|
|
}
|
223
|
|
|
|
224
|
|
|
$path = \Request::path();
|
225
|
|
|
$explode = explode('/', $path);
|
226
|
|
|
|
227
|
|
|
$from = 'form';
|
228
|
|
|
if(in_array('api',$explode)){
|
229
|
|
|
$from = 'api';
|
230
|
|
|
}
|
231
|
|
|
|
232
|
|
|
$via = $from;
|
233
|
|
|
if($version != '' && $version != 'update'){
|
234
|
|
|
$via .= '-'.$version;
|
235
|
|
|
}
|
236
|
|
|
|
237
|
|
|
$error = false;
|
238
|
|
|
$statusCode = 200;
|
239
|
|
|
$title = 'Success';
|
240
|
|
|
$type = 'success';
|
241
|
|
|
$message = 'Data updated successfully';
|
242
|
|
|
$result->update([
|
243
|
|
|
'name' => $request->name
|
244
|
|
|
]);
|
245
|
|
|
return Response::json(array(
|
246
|
|
|
'error' => $error,
|
247
|
|
|
'status' => $statusCode,
|
248
|
|
|
'title' => $title,
|
249
|
|
|
'type' => $type,
|
250
|
|
|
'message' => $message,
|
251
|
|
|
'result' => $result
|
252
|
|
|
));
|
253
|
|
|
}
|
254
|
|
|
|
255
|
|
|
/**
|
256
|
|
|
* Remove the specified resource from storage.
|
257
|
|
|
*
|
258
|
|
|
* @param int $id
|
259
|
|
|
* @return Response
|
260
|
|
|
*/
|
261
|
|
|
public function destroy($id)
|
262
|
|
|
{
|
263
|
|
|
EpormasCity::find($id)->delete();
|
264
|
|
|
$error = false;
|
265
|
|
|
$statusCode = 200;
|
266
|
|
|
$title = 'Success';
|
267
|
|
|
$type = 'success';
|
268
|
|
|
$message = 'Data deleted successfully';
|
269
|
|
|
return Response::json(array(
|
270
|
|
|
'error' => $error,
|
271
|
|
|
'status' => $statusCode,
|
272
|
|
|
'title' => $title,
|
273
|
|
|
'type' => $type,
|
274
|
|
|
'message' => $message
|
275
|
|
|
));
|
276
|
|
|
}
|
277
|
|
|
|
278
|
|
|
}
|
279
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths