Skip to content

Commit

Permalink
Include query and fragment in relative URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
octoberapp committed Jul 13, 2023
1 parent dbc2d56 commit afa7d04
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Html/UrlServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ public function registerRelativeHelper()
$provider = $this->app['url'];

$provider->macro('toRelative', function($url) use ($provider) {
return parse_url($provider->to($url), PHP_URL_PATH);
$fullUrl = $provider->to($url);
return parse_url($fullUrl, PHP_URL_PATH)
. (($query = parse_url($fullUrl, PHP_URL_QUERY)) ? '?' . $query : '')
. (($query = parse_url($fullUrl, PHP_URL_FRAGMENT)) ? '#' . $query : '');
});
}

Expand Down

0 comments on commit afa7d04

Please sign in to comment.