public function slug(Web $web, $slug) { $slug = Slug::where('name', $slug)->firstOrFail(); if ($slug->slug_attribute_id == SlugAttribute::FOR_MENU) { $menu = $slug->menu; $contents = $menu->contents->sortByDesc(function ($content) { return $content->publish_date; }); if (!$contents) { dd('no content'); // show 404 } $first_content = $contents->first(); if ($first_content->url) { return redirect($first_content->url); } if (count($contents) == 1) { $content = $contents->first(); // dd($content->slug); return redirect(action('WelcomeController@slug', ['slug' => $content->slug->name])); } else { // dd($contents); $contents = $contents->take(5); // add skip for pagination return view('main.multi_dynamic_contents', compact('web', 'contents')); } } else { if ($slug->slug_attribute_id == SlugAttribute::FOR_CONTENT) { $content = $slug->content; if ($content->url) { return redirect($content->url); } return view('main.dynamic_content', compact('web', 'content')); } } // show 404 return '404'; }
/** * @param $slug * @return mixed */ private function postBySlug($slug) { return $post = Slug::where('slug', $slug)->firstOrFail()->post; }
public function ClearUpVariables($data, $hour_stamp) { //amend values as I wish $data['hour_stamp'] = $hour_stamp; $data['hour_stamp_flight_number'] = str_replace(' ', '', $hour_stamp . $data['flight_number']); //unique column $data['scheduled_time'] = Carbon::createFromFormat('d.m. H:i', $data['scheduled_time']); //airline code preg_match("|^..|", $data['flight_number'], $output_array_3); $data['airline_code'] = strtolower($output_array_3[0]); if ($data['airline_code'] == "ez") { $data['airline_code'] = "u2"; } //easyjet not using their IATA code U2 but EZY - manual correction //terminal preg_match("|[1-9]|", $data['terminal'], $output_array_4); $data['terminal'] = $output_array_4[0]; //destination $data['destination'] = strtolower($data['destination']); //keep all such data in lowercase (because Sqlite differentiate between Capitals and lower) preg_match("|(.*)\\((.*)\\)|", $data['destination'], $output_array_1); if (count($output_array_1) > 1) { $CitySlashAirport = $output_array_1[1]; $data['country_code'] = $output_array_1[2]; } else { $CitySlashAirport = null; $data['country_code'] = 'xx'; } unset($data['destination']); //in case some strange codes comes $country = Country::where('country_code', $data['country_code']); if (count($country) == 0) { $newcountry = new Country(); $newcountry->country_code = $data['country_code']; $newcountry->country_name = 'Undefined'; $newcountry->save(); } $output_array_2 = preg_split("|\\/|", $CitySlashAirport); $data['city'] = $output_array_2[0]; if (empty($data['city'])) { $data['city'] = 'empty'; } if (count($output_array_2) > 1) { $data['airport'] = $output_array_2[1]; } else { $data['airport'] = null; } //city_slug $slug = new SlugClass(); $data['city_slug'] = $slug->slugify($data['city']); //find if this city_slug is in cities table $city_slug_in_cities = City::where('city_slug', $data['city_slug'])->first(); if (empty($city_slug_in_cities)) { $city_slug_bridge = Slug::where('city_slug_dirty', $data['city_slug'])->first(); if (!empty($city_slug_bridge)) { $data['city_slug'] = $city_slug_bridge->city_slug_clean; echo $data['city_slug']; } } $data = array_map('trim', $data); //trim values return $data; }