public function lga() { $query = \Input::get('z'); $list = \App\Lga::where('state_id', '=', $query)->lists('name', 'id')->all(); if (count($list) > 0) { foreach ($list as $key => $value) { $data[] = array('id' => $key, 'text' => $value); } } else { $data[] = array('id' => '0', 'text' => 'No areas/region found'); } return \Response::json(['data' => $data]); }
/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update(LocationUpdateRequest $request, $id) { $state = State::findOrFail($id); $state->name = $request->input('state'); $state->save(); $lgas = $request->input('lga'); $real = []; $state->lgas()->delete(); foreach ($lgas as $lga) { if ($existingArea = Lga::where('name', $lga)->first()) { $real[] = $existingArea; } else { $newArea = new Lga(); $newArea->name = $lga; $newArea->save(); $real[] = $newArea; } } $state->lgas()->saveMany($real); return redirect("/admin/location/")->withSuccess("Changes saved."); }