public function index() { $languages = Language::orderBy('name', 'asc')->get(); $countries = Country::orderBy('name', 'asc')->get(); $cities = array(); if (count($countries) > 0) { $cities = $countries[0]->cities()->orderBy('name', 'asc')->get(); if (count($cities) > 0) { $lngs_act = $cities[0]->languages()->get(); //find active languages for ($i = 0; $i < count($languages); $i++) { $languages[$i]->active = FALSE; for ($j = 0; $j < count($lngs_act); $j++) { if ($languages[$i]->id == $lngs_act[$j]->id) { $languages[$i]->active = TRUE; break; } } } } } //Debugbar::info($lng_ids[0]->id); Debugbar::info($languages); $data = ['active_menu' => 'cities', 'countries' => $countries, 'cities' => $cities, 'languages' => $languages]; return view('cities', $data); }
public function destroy(Request $request) { //Validation data $customMessages = ['exists' => 'Язык не найден.Возможно он был удален ранее.']; $this->validate($request, ['id' => 'exists:languages,id'], $customMessages); //Remove from DB $lang_rec = Language::find($request->input('id')); $lang_rec->cities()->detach(); $lang_rec->delete(); //Redirect to languages page return redirect()->route('languages'); }