diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 88b76d9..e1ddd27 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -36,4 +36,4 @@ jobs: command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress - name: Execute tests - run: vendor/bin/phpunit --colors --verbose + run: vendor/bin/phpunit --colors diff --git a/src/MultilingualRegistrar.php b/src/MultilingualRegistrar.php index cdb0d00..fff1e6e 100644 --- a/src/MultilingualRegistrar.php +++ b/src/MultilingualRegistrar.php @@ -269,7 +269,7 @@ protected function generateNameForLocaleFromOptions(string $locale, string $key, */ protected function generatePrefixForLocale(string $key, string $locale): ?string { - if ($key === '/' || $this->shouldNotPrefixLocale($locale)) { + if (($key === '/' && ! $this->router->getLastGroupPrefix()) || $this->shouldNotPrefixLocale($locale)) { return null; } diff --git a/tests/RouteTest.php b/tests/RouteTest.php index 7b44ede..3475e43 100644 --- a/tests/RouteTest.php +++ b/tests/RouteTest.php @@ -247,6 +247,23 @@ public function a_route_with_prefix_stack_can_be_registered(): void ); } + /** @test **/ + public function a_root_route_with_prefix_stack_can_be_registered(): void + { + $this->registerTestTranslations(); + + Route::prefix('prefix')->group(static function () { + Route::multilingual('/')->name('test'); + }); + + $this->assertEquals(url('prefix'), localized_route('test')); + + $this->assertEquals( + url('fr/prefixe'), + localized_route('test', [], 'fr') + ); + } + /** @test **/ public function a_view_route_can_be_registered(): void { @@ -569,10 +586,12 @@ protected function registerTestTranslations(): void $this->registerTranslations([ 'en' => [ 'routes.prefix/test' => 'prefix/test', + 'routes.prefix' => 'prefix', 'routes.test' => 'test', ], 'fr' => [ 'routes.prefix/test' => 'prefixe/teste', + 'routes.prefix' => 'prefixe', 'routes.test' => 'teste', ], ]);