Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support root routes in route groups #81

Merged
merged 3 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/MultilingualRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
19 changes: 19 additions & 0 deletions tests/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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',
],
]);
Expand Down
Loading