diff --git a/src/Mcamara/LaravelLocalization/LaravelLocalization.php b/src/Mcamara/LaravelLocalization/LaravelLocalization.php index f2e310b..23d1eae 100644 --- a/src/Mcamara/LaravelLocalization/LaravelLocalization.php +++ b/src/Mcamara/LaravelLocalization/LaravelLocalization.php @@ -282,9 +282,10 @@ public function getLocalizedURL($locale = null, $url = null, $attributes = [], $ } } else { $url = $this->url->to($url); - $url = preg_replace('/'. preg_quote($urlQuery, '/') . '$/', '', $url); } + $url = preg_replace('/'. preg_quote($urlQuery, '/') . '$/', '', $url); + if ($locale && $translatedRoute = $this->findTranslatedRouteByUrl($url, $attributes, $this->currentLocale)) { return $this->getURLFromRouteNameTranslated($locale, $translatedRoute, $attributes, $forceDefaultLocation).$urlQuery; } diff --git a/tests/LocalizerTests.php b/tests/LocalizerTests.php index 4d9609e..855e0fe 100644 --- a/tests/LocalizerTests.php +++ b/tests/LocalizerTests.php @@ -340,6 +340,18 @@ public function testGetLocalizedURLWithQueryStringAndhideDefaultLocaleInURL() ); } + public function testGetLocalizedURLWithQueryStringAndNotTranslatedRoute() + { + app()['request'] = $this->createRequest( + $uri = 'en/about?q=2' + ); + $laravelLocalization = new \Mcamara\LaravelLocalization\LaravelLocalization(); + + $this->assertEquals( + $this->test_url . 'en/about?q=2', + $laravelLocalization->getLocalizedURL() + ); + } /** * @param string $path