public function getUpdate(Request $r) { foreach ($r->id_kec as $key => $id_kec) { $cek = Kecamatan::where('id', $r->kec[$key])->where('id', '<>', $id_kec)->count(); if ($cek > 0) { \Session::flash('gagal', 'Gagal!! Pastikan ID KECAMATAN tidak ada yang sama'); return redirect()->back(); } } DB::transaction(function () use($r) { $table = ['app_air_tawar', 'app_tambak', 'app_jumlah_penduduk', 'app_mangrove_jenis', 'app_mangrove_milik', 'app_mangrove_rehabilitasi', 'app_pemasar', 'app_rumput_laut', 'app_terumbu_jenis_ikan', 'app_terumbu_milik', 'app_terumbu_rehabilitasi']; foreach ($r->id_kec as $key => $id_kec) { DB::table('kecamatan')->where('id', $id_kec)->update(['id' => $r->kec[$key]]); DB::table('desa')->where('id_kecamatan', $id_kec)->update(['id_kecamatan' => $r->kec[$key]]); foreach ($table as $val) { DB::table($val)->where('kecamatan', $id_kec)->update(['kecamatan' => $r->kec[$key]]); } } }); \Session::flash('success', 'Berhasil mengubah data'); return redirect()->back(); }
public function listkec() { $kab = Input::get('option'); $kec = ['0' => 'Select kabupaten first'] + Kecamatan::where('kabupaten_id', '=', $kab)->lists('nama', 'id')->toArray(); return Response::make($kec); }
}]); Route::resources(['instansi' => 'InstansiController', 'bantuan' => 'BantuanController', 'kriteria' => 'KriteriaController', 'indikator' => 'IndikatorController']); Route::group(['prefix' => 'region', 'namespace' => 'Region'], function () { Route::get('/', function () { return redirect()->url('admin/kabupaten'); }); Route::resources(['provinsi' => 'ProvinsiController', 'kabupaten' => 'KabupatenController', 'kecamatan' => 'KecamatanController', 'desa' => 'DesaController']); Route::get('get/{region}/{id}', ['as' => 'getRegion', 'uses' => function ($r, $id) { $data = []; if ($r == 'kabupaten') { foreach (\App\Kabupaten::where('provinsi_id', $id)->get() as $list) { $data = array_merge_recursive($data, [['id' => $list->id, 'text' => $list->label]]); } } if ($r == 'kecamatan') { foreach (\App\Kecamatan::where('kabupaten_id', $id)->get() as $list) { $data = array_merge_recursive($data, [['id' => $list->id, 'text' => $list->label]]); } } if ($r == 'desa') { foreach (\App\Desa::where('kecamatan_id', $id)->get() as $list) { $data = array_merge_recursive($data, [['id' => $list->id, 'text' => $list->label]]); } } return $data; }]); }); }); Route::group(['prefix' => 'admin/kecamatan', 'middleware' => 'UAC:kecamatan', 'namespace' => 'Admin\\Kecamatan'], function () { Route::get('/', ['as' => 'admin.kecamatan.landing', 'uses' => function () { return view('admin_template');