/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { $regions = Region::all(); $countries = Country::orderBy('name', 'asc')->get(); $offers_air = Offer_air::orderBy('offerId', 'asc')->get(); return view('cms/tags/create')->with('regions', $regions)->with('countries', $countries)->with('offers_air', $offers_air); }
/** * Show the form for editing the specified resource. * * @param int $id_region * @return \Illuminate\Http\Response */ public function edit($id_region) { $region = Region::findOrFail($id_region); $region_countries = $region->countries()->getResults()->keyBy('code')->toArray(); $all_countries = Country::orderBy('name', 'asc')->get(); $all_countries_ordered_list = collect(); $filtered_country_list = collect(); foreach ($all_countries as $country) { if (array_key_exists($country->code, $region_countries)) { $filtered_country_list->push($country->code); } } $current_country_letter = '-'; $helper_collection = collect(); $countries_length = $all_countries->count() - 1; foreach ($all_countries as $key => $country) { $country_letter = strtolower($country->name[0]); if ($country_letter != $current_country_letter) { if ($current_country_letter != '-') { $all_countries_ordered_list->put(strtoupper($current_country_letter), $helper_collection); } $current_country_letter = $country_letter; $helper_collection = collect(); } $helper_collection->push($country); if ($key == $countries_length) { $all_countries_ordered_list->put(strtoupper($current_country_letter), $helper_collection); } } return view('cms/regions/edit')->with('region', $region)->with('countries', $all_countries)->with('countries_ordered_list', $all_countries_ordered_list)->with('filtered_country_list', $filtered_country_list); }