@@ -41,10 +41,6 @@ public function route($name, $parameters = [], $absolute = true, $locale = null)
4141 return parent ::route ($ name , $ parameters , $ absolute );
4242 }
4343
44- // Normalize the route name by removing any locale prefix.
45- // We will prepend the applicable locale manually.
46- $ name = $ this ->stripLocaleFromRouteName ($ name );
47-
4844 // Cache the current locale so we can change it
4945 // to automatically resolve any translatable
5046 // route parameters such as slugs.
@@ -54,12 +50,27 @@ public function route($name, $parameters = [], $absolute = true, $locale = null)
5450 // as a prefix for the route name.
5551 $ locale = $ locale ?: $ currentLocale ;
5652
53+ // Normalize the route name by removing any locale prefix.
54+ // We will prepend the applicable locale manually.
55+ $ baseName = $ this ->stripLocaleFromRouteName ($ name );
56+
57+ // If the route has a name (not just the locale prefix)
58+ // add the requested locale prefix.
59+ $ newName = $ baseName ? "{$ locale }. {$ baseName }" : '' ;
60+
61+ // If the new localized name does not exist, but the unprefixed route name does,
62+ // someone might be calling "route($name, [], true, $locale)" on a non localized route.
63+ // In that case, resolve the unprefixed route name.
64+ if (Route::has ($ baseName ) && ! Route::has ($ newName )) {
65+ $ newName = $ baseName ;
66+ }
67+
5768 // Update the current locale if needed.
5869 if ($ locale !== $ currentLocale ) {
5970 App::setLocale ($ locale );
6071 }
6172
62- $ url = parent ::route ("{ $ locale } . { $ name }" , $ parameters , $ absolute );
73+ $ url = parent ::route ($ newName , $ parameters , $ absolute );
6374
6475 // Restore the current locale if needed.
6576 if ($ locale !== $ currentLocale ) {
0 commit comments