Skip to content

Commit db984c8

Browse files
committed
Return a URL with query string from Route::localizedUrl()
1 parent eaf7cff commit db984c8

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/UrlBuilder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ public function build($absolute = true)
4444
{
4545
$host = $absolute ? $this->get('scheme') . '://' . $this->get('host') . $this->get('port') : '';
4646
$path = '/' . trim($this->get('path'), '/');
47+
$query = $this->get('query') ? '?' . $this->get('query') : '';
4748

48-
return $host . $path;
49+
return $host . $path . $query;
4950
}
5051

5152
/**

tests/Unit/Macros/LocalizedUrlMacroTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,28 @@ public function it_generates_non_absolute_urls_for_non_existing_routes()
564564
$this->assertEquals('/en/route/does/not/exist', trim($response->original));
565565
}
566566

567+
/** @test */
568+
public function it_returns_a_url_with_query_string()
569+
{
570+
$this->setSupportedLocales(['en', 'nl']);
571+
572+
Route::get('route', function () {
573+
return [
574+
'current' => Route::localizedUrl(),
575+
'en' => Route::localizedUrl('en'),
576+
'nl' => Route::localizedUrl('nl'),
577+
];
578+
});
579+
580+
$response = $this->call('GET', '/route?another=one&param=value');
581+
$response->assertOk();
582+
$this->assertEquals([
583+
'current' => url('/route?another=one&param=value'),
584+
'en' => url('/route?another=one&param=value'),
585+
'nl' => url('/route?another=one&param=value'),
586+
], $response->original);
587+
}
588+
567589
/**
568590
* Set a custom view path so Laravel will find our custom 440 error view.
569591
*

0 commit comments

Comments
 (0)