Skip to content

Commit 0cb7b99

Browse files
committed
Generate correct URL's when using domains (#73)
1 parent 072b710 commit 0cb7b99

File tree

2 files changed

+62
-4
lines changed

2 files changed

+62
-4
lines changed

src/UrlGenerator.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,9 @@ public function route($name, $parameters = [], $absolute = true, $locale = null)
5555
$locale = $locale ?: $currentLocale;
5656

5757
// Check if the locale is supported
58-
if (!in_array($locale, config('localized-routes.supported-locales'))) {
58+
if ( ! in_array($locale, $this->getSupportedLocales())) {
5959
// Use a fallback locale if provided
60-
if (config('localized-routes.fallback_locale')) {
61-
$locale = config('localized-routes.fallback_locale');
62-
}
60+
$locale = Config::get('localized-routes.fallback_locale', $locale);
6361
}
6462

6563
// Normalize the route name by removing any locale prefix.

tests/Unit/Macros/LocalizedUrlMacroTest.php

+60
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,66 @@ public function it_returns_the_current_url_for_existing_non_localized_routes()
374374
], $response->original);
375375
}
376376

377+
/** @test */
378+
public function it_returns_the_url_for_existing_unnamed_localized_routes_using_domains()
379+
{
380+
$this->withoutExceptionHandling();
381+
$this->setSupportedLocales([
382+
'en' => 'domain.test',
383+
'nl' => 'nl.domain.test',
384+
]);
385+
$this->setAppLocale('en');
386+
$this->setFallbackLocale('en');
387+
388+
Route::localized(function () {
389+
Route::get('/', function () {
390+
return [
391+
'current' => Route::localizedUrl(),
392+
'en' => Route::localizedUrl('en'),
393+
'nl' => Route::localizedUrl('nl'),
394+
];
395+
});
396+
});
397+
398+
$response = $this->call('GET', 'http://domain.test');
399+
$response->assertOk();
400+
$this->assertEquals([
401+
'current' => 'http://domain.test',
402+
'en' => 'http://domain.test',
403+
'nl' => 'http://nl.domain.test',
404+
], $response->original);
405+
}
406+
407+
/** @test */
408+
public function it_returns_the_url_for_existing_named_localized_routes_using_domains()
409+
{
410+
$this->withoutExceptionHandling();
411+
$this->setSupportedLocales([
412+
'en' => 'domain.test',
413+
'nl' => 'nl.domain.test',
414+
]);
415+
$this->setAppLocale('en');
416+
$this->setFallbackLocale('en');
417+
418+
Route::localized(function () {
419+
Route::get('/', function () {
420+
return [
421+
'current' => Route::localizedUrl(),
422+
'en' => Route::localizedUrl('en'),
423+
'nl' => Route::localizedUrl('nl'),
424+
];
425+
})->name('route');
426+
});
427+
428+
$response = $this->call('GET', 'http://domain.test');
429+
$response->assertOk();
430+
$this->assertEquals([
431+
'current' => 'http://domain.test',
432+
'en' => 'http://domain.test',
433+
'nl' => 'http://nl.domain.test',
434+
], $response->original);
435+
}
436+
377437
/** @test */
378438
public function the_macro_does_not_blow_up_on_a_default_404_error()
379439
{

0 commit comments

Comments
 (0)