|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bantenprov\Zona\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
/* Require */ |
|
6
|
|
|
use App\Http\Controllers\Controller; |
|
7
|
|
|
use Illuminate\Http\Request; |
|
8
|
|
|
use Illuminate\Support\Facades\DB; |
|
9
|
|
|
use Bantenprov\Zona\Facades\ZonaFacade; |
|
10
|
|
|
|
|
11
|
|
|
/* Models */ |
|
12
|
|
|
use Bantenprov\Zona\Models\Bantenprov\Zona\Zona; |
|
13
|
|
|
use Bantenprov\Siswa\Models\Bantenprov\Siswa\Siswa; |
|
14
|
|
|
use Bantenprov\Sekolah\Models\Bantenprov\Sekolah\Sekolah; |
|
15
|
|
|
use App\User; |
|
16
|
|
|
use Bantenprov\Nilai\Models\Bantenprov\Nilai\Nilai; |
|
17
|
|
|
use Bantenprov\Sekolah\Models\Bantenprov\Sekolah\AdminSekolah; |
|
18
|
|
|
|
|
19
|
|
|
/* Etc */ |
|
20
|
|
|
use Validator; |
|
21
|
|
|
use Auth; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The ZonaController class. |
|
25
|
|
|
* |
|
26
|
|
|
* @package Bantenprov\Zona |
|
27
|
|
|
* @author bantenprov <[email protected]> |
|
28
|
|
|
*/ |
|
29
|
|
|
class ZonaController extends Controller |
|
30
|
|
|
{ |
|
31
|
|
|
protected $zona; |
|
32
|
|
|
protected $siswa; |
|
33
|
|
|
protected $sekolah; |
|
34
|
|
|
protected $user; |
|
35
|
|
|
protected $nilai; |
|
36
|
|
|
protected $admin_sekolah; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Create a new controller instance. |
|
40
|
|
|
* |
|
41
|
|
|
* @return void |
|
|
|
|
|
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->zona = new Zona; |
|
46
|
|
|
$this->siswa = new Siswa; |
|
47
|
|
|
$this->sekolah = new Sekolah; |
|
48
|
|
|
$this->user = new User; |
|
49
|
|
|
$this->nilai = new Nilai; |
|
50
|
|
|
$this->admin_sekolah = new AdminSekolah; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Display a listing of the resource. |
|
55
|
|
|
* |
|
56
|
|
|
* @return \Illuminate\Http\Response |
|
57
|
|
|
*/ |
|
58
|
|
|
public function index(Request $request) |
|
59
|
|
|
{ |
|
60
|
|
|
$admin_sekolah = $this->admin_sekolah->where('admin_sekolah_id', Auth::user()->id)->first(); |
|
61
|
|
|
|
|
62
|
|
|
if(is_null($admin_sekolah) && $this->checkRole(['superadministrator']) === false){ |
|
63
|
|
|
$response = []; |
|
64
|
|
|
return response()->json($response) |
|
65
|
|
|
->header('Access-Control-Allow-Origin', '*') |
|
66
|
|
|
->header('Access-Control-Allow-Methods', 'GET'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
if (request()->has('sort')) { |
|
70
|
|
|
list($sortCol, $sortDir) = explode('|', request()->sort); |
|
71
|
|
|
|
|
72
|
|
|
if($this->checkRole(['superadministrator'])){ |
|
73
|
|
|
$query = $this->zona->orderBy($sortCol, $sortDir); |
|
74
|
|
|
}else{ |
|
75
|
|
|
$query = $this->zona->where('user_id', $admin_sekolah->admin_sekolah_id)->orderBy($sortCol, $sortDir); |
|
76
|
|
|
} |
|
77
|
|
|
} else { |
|
78
|
|
|
if($this->checkRole(['superadministrator'])){ |
|
79
|
|
|
$query = $this->zona->orderBy('id', 'asc'); |
|
80
|
|
|
}else{ |
|
81
|
|
|
$query = $this->zona->where('user_id', $admin_sekolah->admin_sekolah_id)->orderBy('id', 'asc'); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
if ($request->exists('filter')) { |
|
86
|
|
|
if($this->checkRole(['superadministrator'])){ |
|
87
|
|
View Code Duplication |
$query->where(function($q) use($request) { |
|
|
|
|
|
|
88
|
|
|
$value = "%{$request->filter}%"; |
|
89
|
|
|
|
|
90
|
|
|
$q->where('sekolah_id', 'like', $value) |
|
91
|
|
|
->orWhere('admin_sekolah_id', 'like', $value); |
|
92
|
|
|
}); |
|
93
|
|
|
}else{ |
|
94
|
|
View Code Duplication |
$query->where(function($q) use($request, $admin_sekolah) { |
|
|
|
|
|
|
95
|
|
|
$value = "%{$request->filter}%"; |
|
96
|
|
|
|
|
97
|
|
|
$q->where('sekolah_id', $admin_sekolah->sekolah_id)->where('sekolah_id', 'like', $value); |
|
98
|
|
|
}); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
$perPage = request()->has('per_page') ? (int) request()->per_page : null; |
|
104
|
|
|
|
|
105
|
|
|
$response = $query->with(['siswa', 'sekolah', 'user'])->paginate($perPage); |
|
106
|
|
|
|
|
107
|
|
|
return response()->json($response) |
|
108
|
|
|
->header('Access-Control-Allow-Origin', '*') |
|
109
|
|
|
->header('Access-Control-Allow-Methods', 'GET'); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Display a listing of the resource. |
|
114
|
|
|
* |
|
115
|
|
|
* @return \Illuminate\Http\Response |
|
116
|
|
|
*/ |
|
117
|
|
View Code Duplication |
public function get() |
|
|
|
|
|
|
118
|
|
|
{ |
|
119
|
|
|
$zonas = $this->zona->with(['siswa', 'sekolah', 'user'])->get(); |
|
120
|
|
|
|
|
121
|
|
|
$response['zonas'] = $zonas; |
|
|
|
|
|
|
122
|
|
|
$response['error'] = false; |
|
123
|
|
|
$response['message'] = 'Success'; |
|
124
|
|
|
$response['status'] = true; |
|
125
|
|
|
|
|
126
|
|
|
return response()->json($response); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Show the form for creating a new resource. |
|
131
|
|
|
* |
|
132
|
|
|
* @return \Illuminate\Http\Response |
|
133
|
|
|
*/ |
|
134
|
|
|
public function create() |
|
135
|
|
|
{ |
|
136
|
|
|
$user_id = isset(Auth::User()->id) ? Auth::User()->id : null; |
|
137
|
|
|
$zona = $this->zona->getAttributes(); |
|
138
|
|
|
//$siswas = $this->siswa->getAttributes(); |
|
|
|
|
|
|
139
|
|
|
$sekolahs = $this->sekolah->getAttributes(); |
|
140
|
|
|
$users = $this->user->getAttributes(); |
|
|
|
|
|
|
141
|
|
|
$users_special = $this->user->all(); |
|
142
|
|
|
$users_standar = $this->user->findOrFail($user_id); |
|
143
|
|
|
$current_user = Auth::User(); |
|
144
|
|
|
|
|
145
|
|
|
$admin_sekolah = $this->admin_sekolah->where('admin_sekolah_id', Auth::user()->id)->first(); |
|
146
|
|
|
|
|
147
|
|
|
if($this->checkRole(['superadministrator'])){ |
|
148
|
|
|
$siswas = $this->siswa->all(); |
|
149
|
|
|
}else{ |
|
150
|
|
|
$sekolah_id = $admin_sekolah->sekolah_id; |
|
151
|
|
|
$siswas = $this->siswa->where('sekolah_id', $sekolah_id)->get(); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
foreach ($siswas as $siswa) { |
|
155
|
|
|
array_set($siswa, 'label', $siswa->nomor_un.' - '.$siswa->nama_siswa); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
foreach ($sekolahs as $sekolah) { |
|
159
|
|
|
array_set($sekolah, 'label', $sekolah->nama); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
$role_check = Auth::User()->hasRole(['superadministrator','administrator']); |
|
163
|
|
|
|
|
164
|
|
View Code Duplication |
if ($role_check) { |
|
|
|
|
|
|
165
|
|
|
$user_special = true; |
|
166
|
|
|
|
|
167
|
|
|
foreach ($users_special as $user) { |
|
168
|
|
|
array_set($user, 'label', $user->name); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
$users = $users_special; |
|
172
|
|
|
} else { |
|
173
|
|
|
$user_special = false; |
|
174
|
|
|
|
|
175
|
|
|
array_set($users_standar, 'label', $users_standar->name); |
|
176
|
|
|
|
|
177
|
|
|
$users = $users_standar; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
array_set($current_user, 'label', $current_user->name); |
|
181
|
|
|
|
|
182
|
|
|
$response['zona'] = $zona; |
|
|
|
|
|
|
183
|
|
|
$response['siswa'] = $siswas; |
|
184
|
|
|
$response['sekolahs'] = $sekolahs; |
|
185
|
|
|
$response['users'] = $users; |
|
186
|
|
|
$response['user_special'] = $user_special; |
|
187
|
|
|
$response['current_user'] = $current_user; |
|
188
|
|
|
$response['error'] = false; |
|
189
|
|
|
$response['message'] = 'Success'; |
|
190
|
|
|
$response['status'] = true; |
|
191
|
|
|
|
|
192
|
|
|
return response()->json($response); |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Store a newly created resource in storage. |
|
197
|
|
|
* |
|
198
|
|
|
* @param \Illuminate\Http\Request $request |
|
199
|
|
|
* @return \Illuminate\Http\Response |
|
200
|
|
|
*/ |
|
201
|
|
|
public function store(Request $request) |
|
202
|
|
|
{ |
|
203
|
|
|
$zona = $this->zona; |
|
204
|
|
|
|
|
205
|
|
|
$validator = Validator::make($request->all(), [ |
|
206
|
|
|
'nomor_un' => "required|exists:{$this->siswa->getTable()},nomor_un|unique:{$this->zona->getTable()},nomor_un,NULL,id,deleted_at,NULL", |
|
207
|
|
|
// 'sekolah_id' => "required|exists:{$this->sekolah->getTable()},id", |
|
|
|
|
|
|
208
|
|
|
// 'zona_siswa' => "required|exists:{$this->city->getTable()},id", |
|
|
|
|
|
|
209
|
|
|
// 'zona_sekolah' => "required|exists:{$this->village->getTable()},id", |
|
|
|
|
|
|
210
|
|
|
// 'lokasi_siswa' => "required|exists:{$this->district->getTable()},id", |
|
|
|
|
|
|
211
|
|
|
// 'lokasi_sekolah' => "required|exists:{$this->village->getTable()},id", |
|
|
|
|
|
|
212
|
|
|
// 'nilai' => 'required|numeric', |
|
|
|
|
|
|
213
|
|
|
'user_id' => "required|exists:{$this->user->getTable()},id", |
|
214
|
|
|
]); |
|
215
|
|
|
|
|
216
|
|
View Code Duplication |
if ($validator->fails()) { |
|
|
|
|
|
|
217
|
|
|
$error = true; |
|
218
|
|
|
$message = $validator->errors()->first(); |
|
219
|
|
|
} else { |
|
220
|
|
|
$nomor_un = $request->input('nomor_un'); |
|
221
|
|
|
$siswa = $this->siswa->where('nomor_un', $nomor_un)->with(['sekolah'])->first(); |
|
222
|
|
|
$zona_siswa = substr($siswa->village_id, 0, 6); |
|
223
|
|
|
$zona_sekolah = substr($siswa->sekolah->village_id, 0, 6); |
|
224
|
|
|
$lokasi_siswa = $siswa->village_id; |
|
225
|
|
|
$lokasi_sekolah = $siswa->sekolah->village_id; |
|
226
|
|
|
|
|
227
|
|
|
$zona->nomor_un = $nomor_un; |
|
228
|
|
|
$zona->sekolah_id = $siswa->sekolah->id; |
|
229
|
|
|
$zona->zona_siswa = $zona_siswa; |
|
230
|
|
|
$zona->zona_sekolah = $zona_sekolah; |
|
231
|
|
|
$zona->lokasi_siswa = $lokasi_siswa; |
|
232
|
|
|
$zona->lokasi_sekolah = $lokasi_sekolah; |
|
233
|
|
|
$zona->nilai = $this->zona->nilai($lokasi_siswa, $lokasi_sekolah); |
|
234
|
|
|
$zona->user_id = $request->input('user_id'); |
|
235
|
|
|
|
|
236
|
|
|
$nilai = $this->nilai->updateOrCreate( |
|
237
|
|
|
[ |
|
238
|
|
|
'nomor_un' => $zona->nomor_un, |
|
239
|
|
|
], |
|
240
|
|
|
[ |
|
241
|
|
|
'nomor_un' => $zona->nomor_un, |
|
242
|
|
|
'zona' => $zona->nilai, |
|
243
|
|
|
'kegiatan_id' => null, |
|
244
|
|
|
'total' => null, |
|
245
|
|
|
'user_id' => $zona->user_id, |
|
246
|
|
|
] |
|
247
|
|
|
); |
|
248
|
|
|
|
|
249
|
|
|
DB::beginTransaction(); |
|
250
|
|
|
|
|
251
|
|
|
if ($zona->save() && $nilai->save()) |
|
252
|
|
|
{ |
|
253
|
|
|
DB::commit(); |
|
254
|
|
|
|
|
255
|
|
|
$error = false; |
|
256
|
|
|
$message = 'Success'; |
|
257
|
|
|
} else { |
|
258
|
|
|
DB::rollBack(); |
|
259
|
|
|
|
|
260
|
|
|
$error = true; |
|
261
|
|
|
$message = 'Failed'; |
|
262
|
|
|
} |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
$response['zona'] = $zona; |
|
|
|
|
|
|
266
|
|
|
$response['error'] = $error; |
|
267
|
|
|
$response['message'] = $message; |
|
268
|
|
|
$response['status'] = true; |
|
269
|
|
|
|
|
270
|
|
|
return response()->json($response); |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
|
/** |
|
274
|
|
|
* Display the specified resource. |
|
275
|
|
|
* |
|
276
|
|
|
* @param \App\Zona $zona |
|
|
|
|
|
|
277
|
|
|
* @return \Illuminate\Http\Response |
|
278
|
|
|
*/ |
|
279
|
|
View Code Duplication |
public function show($id) |
|
|
|
|
|
|
280
|
|
|
{ |
|
281
|
|
|
$zona = $this->zona->with(['siswa', 'sekolah', 'user'])->findOrFail($id); |
|
282
|
|
|
|
|
283
|
|
|
$response['zona'] = $zona; |
|
|
|
|
|
|
284
|
|
|
$response['error'] = false; |
|
285
|
|
|
$response['message'] = 'Success'; |
|
286
|
|
|
$response['status'] = true; |
|
287
|
|
|
|
|
288
|
|
|
return response()->json($response); |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
|
/** |
|
292
|
|
|
* Show the form for editing the specified resource. |
|
293
|
|
|
* |
|
294
|
|
|
* @param \App\Zona $zona |
|
|
|
|
|
|
295
|
|
|
* @return \Illuminate\Http\Response |
|
296
|
|
|
*/ |
|
297
|
|
|
public function edit($id) |
|
298
|
|
|
{ |
|
299
|
|
|
$user_id = isset(Auth::User()->id) ? Auth::User()->id : null; |
|
300
|
|
|
$zona = $this->zona->with(['siswa', 'sekolah', 'user'])->findOrFail($id); |
|
301
|
|
|
$siswas = $this->siswa->getAttributes(); |
|
302
|
|
|
$sekolahs = $this->sekolah->getAttributes(); |
|
303
|
|
|
$users = $this->user->getAttributes(); |
|
|
|
|
|
|
304
|
|
|
$users_special = $this->user->all(); |
|
305
|
|
|
$users_standar = $this->user->findOrFail($user_id); |
|
306
|
|
|
$current_user = Auth::User(); |
|
307
|
|
|
|
|
308
|
|
|
$role_check = Auth::User()->hasRole(['superadministrator','administrator']); |
|
309
|
|
|
|
|
310
|
|
|
if ($zona->user !== null) { |
|
311
|
|
|
array_set($zona->user, 'label', $zona->user->name); |
|
312
|
|
|
} |
|
313
|
|
|
|
|
314
|
|
View Code Duplication |
if ($role_check) { |
|
|
|
|
|
|
315
|
|
|
$user_special = true; |
|
316
|
|
|
|
|
317
|
|
|
foreach ($users_special as $user) { |
|
318
|
|
|
array_set($user, 'label', $user->name); |
|
319
|
|
|
} |
|
320
|
|
|
|
|
321
|
|
|
$users = $users_special; |
|
322
|
|
|
} else { |
|
323
|
|
|
$user_special = false; |
|
324
|
|
|
|
|
325
|
|
|
array_set($users_standar, 'label', $users_standar->name); |
|
326
|
|
|
|
|
327
|
|
|
$users = $users_standar; |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
array_set($current_user, 'label', $current_user->name); |
|
331
|
|
|
|
|
332
|
|
|
$response['zona'] = $zona; |
|
|
|
|
|
|
333
|
|
|
$response['siswas'] = $siswas; |
|
334
|
|
|
$response['sekolahs'] = $sekolahs; |
|
335
|
|
|
$response['users'] = $users; |
|
336
|
|
|
$response['user_special'] = $user_special; |
|
337
|
|
|
$response['current_user'] = $current_user; |
|
338
|
|
|
$response['error'] = false; |
|
339
|
|
|
$response['message'] = 'Success'; |
|
340
|
|
|
$response['status'] = true; |
|
341
|
|
|
|
|
342
|
|
|
return response()->json($response); |
|
343
|
|
|
} |
|
344
|
|
|
|
|
345
|
|
|
/** |
|
346
|
|
|
* Update the specified resource in storage. |
|
347
|
|
|
* |
|
348
|
|
|
* @param \Illuminate\Http\Request $request |
|
349
|
|
|
* @param \App\Zona $zona |
|
|
|
|
|
|
350
|
|
|
* @return \Illuminate\Http\Response |
|
351
|
|
|
*/ |
|
352
|
|
|
public function update(Request $request, $id) |
|
353
|
|
|
{ |
|
354
|
|
|
$zona = $this->zona->with(['siswa', 'sekolah', 'user'])->findOrFail($id); |
|
355
|
|
|
|
|
356
|
|
|
$validator = Validator::make($request->all(), [ |
|
357
|
|
|
// 'nomor_un' => "required|exists:{$this->siswa->getTable()},nomor_un|unique:{$this->zona->getTable()},nomor_un,{$id},id,deleted_at,NULL", |
|
|
|
|
|
|
358
|
|
|
// 'sekolah_id' => "required|exists:{$this->sekolah->getTable()},id", |
|
|
|
|
|
|
359
|
|
|
// 'zona_siswa' => "required|exists:{$this->city->getTable()},id", |
|
|
|
|
|
|
360
|
|
|
// 'zona_sekolah' => "required|exists:{$this->village->getTable()},id", |
|
|
|
|
|
|
361
|
|
|
// 'lokasi_siswa' => "required|exists:{$this->district->getTable()},id", |
|
|
|
|
|
|
362
|
|
|
// 'lokasi_sekolah' => "required|exists:{$this->village->getTable()},id", |
|
|
|
|
|
|
363
|
|
|
// 'nilai' => 'required|numeric', |
|
|
|
|
|
|
364
|
|
|
'user_id' => "required|exists:{$this->user->getTable()},id", |
|
365
|
|
|
]); |
|
366
|
|
|
|
|
367
|
|
View Code Duplication |
if ($validator->fails()) { |
|
|
|
|
|
|
368
|
|
|
$error = true; |
|
369
|
|
|
$message = $validator->errors()->first(); |
|
370
|
|
|
} else { |
|
371
|
|
|
$nomor_un = $zona->nomor_un; // $request->input('nomor_un'); |
|
|
|
|
|
|
372
|
|
|
$siswa = $this->siswa->where('nomor_un', $nomor_un)->with(['sekolah'])->first(); |
|
373
|
|
|
$zona_siswa = substr($siswa->village_id, 0, 6); |
|
374
|
|
|
$zona_sekolah = substr($siswa->sekolah->village_id, 0, 6); |
|
375
|
|
|
$lokasi_siswa = $siswa->village_id; |
|
376
|
|
|
$lokasi_sekolah = $siswa->sekolah->village_id; |
|
377
|
|
|
|
|
378
|
|
|
$zona->nomor_un = $nomor_un; |
|
379
|
|
|
$zona->sekolah_id = $siswa->sekolah->id; |
|
380
|
|
|
$zona->zona_siswa = $zona_siswa; |
|
381
|
|
|
$zona->zona_sekolah = $zona_sekolah; |
|
382
|
|
|
$zona->lokasi_siswa = $lokasi_siswa; |
|
383
|
|
|
$zona->lokasi_sekolah = $lokasi_sekolah; |
|
384
|
|
|
$zona->nilai = $this->zona->nilai($lokasi_siswa, $lokasi_sekolah); |
|
385
|
|
|
$zona->user_id = $request->input('user_id'); |
|
386
|
|
|
|
|
387
|
|
|
$nilai = $this->nilai->updateOrCreate( |
|
388
|
|
|
[ |
|
389
|
|
|
'nomor_un' => $zona->nomor_un, |
|
390
|
|
|
], |
|
391
|
|
|
[ |
|
392
|
|
|
'nomor_un' => $zona->nomor_un, |
|
393
|
|
|
'zona' => $zona->nilai, |
|
394
|
|
|
'kegiatan_id' => null, |
|
395
|
|
|
'total' => null, |
|
396
|
|
|
'user_id' => $zona->user_id, |
|
397
|
|
|
] |
|
398
|
|
|
); |
|
399
|
|
|
|
|
400
|
|
|
DB::beginTransaction(); |
|
401
|
|
|
|
|
402
|
|
|
if ($zona->save() && $nilai->save()) |
|
403
|
|
|
{ |
|
404
|
|
|
DB::commit(); |
|
405
|
|
|
|
|
406
|
|
|
$error = false; |
|
407
|
|
|
$message = 'Success'; |
|
408
|
|
|
} else { |
|
409
|
|
|
DB::rollBack(); |
|
410
|
|
|
|
|
411
|
|
|
$error = true; |
|
412
|
|
|
$message = 'Failed'; |
|
413
|
|
|
} |
|
414
|
|
|
} |
|
415
|
|
|
|
|
416
|
|
|
$response['zona'] = $zona; |
|
|
|
|
|
|
417
|
|
|
$response['error'] = $error; |
|
418
|
|
|
$response['message'] = $message; |
|
419
|
|
|
$response['status'] = true; |
|
420
|
|
|
|
|
421
|
|
|
return response()->json($response); |
|
422
|
|
|
} |
|
423
|
|
|
|
|
424
|
|
|
/** |
|
425
|
|
|
* Remove the specified resource from storage. |
|
426
|
|
|
* |
|
427
|
|
|
* @param \App\Zona $zona |
|
|
|
|
|
|
428
|
|
|
* @return \Illuminate\Http\Response |
|
429
|
|
|
*/ |
|
430
|
|
View Code Duplication |
public function destroy($id) |
|
|
|
|
|
|
431
|
|
|
{ |
|
432
|
|
|
$zona = $this->zona->findOrFail($id); |
|
433
|
|
|
|
|
434
|
|
|
if ($zona->delete()) { |
|
435
|
|
|
$response['message'] = 'Success'; |
|
|
|
|
|
|
436
|
|
|
$response['success'] = true; |
|
437
|
|
|
$response['status'] = true; |
|
438
|
|
|
} else { |
|
439
|
|
|
$response['message'] = 'Failed'; |
|
|
|
|
|
|
440
|
|
|
$response['success'] = false; |
|
441
|
|
|
$response['status'] = false; |
|
442
|
|
|
} |
|
443
|
|
|
|
|
444
|
|
|
return json_encode($response); |
|
445
|
|
|
} |
|
446
|
|
|
|
|
447
|
|
|
protected function checkRole($role = array()) |
|
448
|
|
|
{ |
|
449
|
|
|
return Auth::user()->hasRole($role); |
|
450
|
|
|
} |
|
451
|
|
|
} |
|
452
|
|
|
|
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.