/** * Return an url in the default locale * * @param $url * @return string */ function untranslateURL($url) { $t = app('translator') ?: new TransLaravel(); // Parse url $arrURL = parse_url($url); $segments = explode('/', $arrURL['path']); if ($t->isLocale($segments[0])) { array_shift($segments); } if (array_last($segments) == '') { array_pop($segments); } $path = implode('/', $segments); $newPath = Languages::whereValue($path); if ($newPath->count() == 0) { $newPath = $path; } else { $newPath = $newPath->first()->route; } $returnURL = ''; $returnURL .= isset($arrURL['scheme']) ? $arrURL['scheme'] . '://' : ''; $returnURL .= isset($arrURL['host']) ? $arrURL['host'] : ''; $returnURL .= isset($arrURL['port']) && $arrURL['port'] != 80 ? ':' . $arrURL['port'] : ''; $returnURL .= '/' . config('app.fallback_language') . '/' . $newPath; $returnURL .= isset($arrURL['query']) ? '?' . $arrURL['query'] : ''; $returnURL .= isset($arrURL['fragment']) ? '#' . $arrURL['fragment'] : ''; return str_replace('//', '/', $returnURL); }