Skip to content

Commit

Permalink
Merge pull request #81 from fyrts/bugfix/group-prefix-slash
Browse files Browse the repository at this point in the history
Support root routes in route groups
  • Loading branch information
chinleung authored Mar 27, 2024
2 parents 66a7e9b + 06239cf commit d1e2455
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
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

0 comments on commit d1e2455

Please sign in to comment.