/** * Get Desa * * @param Request $request * @return json */ public function getDesa(Request $request, $desaId = false) { $desa = $this->desa; $kecId = $request->input('kec_id'); $kodePos = $request->input('kode_pos'); $limit = $request->has('limit') ? $request->input('limit') : 100; $getMethod = "get"; $result = $desa; if ($desaId) { $getMethod = "first"; $result = $result->whereDesaid($desaId); } // Kec id if ($kecId) { $result = $result->whereKecamatanid($kecId); } // kode pos if ($kodePos) { $result = $result->whereKodepos($kodePos); } $result = $result->limit($limit)->{$getMethod}(); foreach ($result as $index => $desa) { $result[$index]['kecamatan'] = $this->kecamatan->whereKecamatanid($desa['kecamatanid'])->first(); unset($result[$index]['kecamatanid']); } return $result ? $result : []; }
private function getDetail($anak) { return ['desa' => $this->desa->whereDesaid($anak['desa_id'])->first(), 'id_type' => $this->idType->whereValue($anak['id_type'])->first(), 'sekolah_terakhir' => $this->lastSchool->whereValue($anak['sekolah_terakhir'])->first(), 'kecamatan' => $this->kecamatan->whereKecamatanid($anak['kec_id'])->first(), 'kabupaten' => $this->kabupaten->whereKabupatenid($anak['kab_id'])->first(), 'provinsi' => $this->provinsi->whereProvinsiid($anak['prov_id'])->first()]; }