framework
framework copied to clipboard
Using the Route helper function with absolute paths
I've got a Themosis 2.0.6 project which is not sat in the web servers root, for example http://staging-site-example.com/project/htdocs/
and I have a named custom route.
As such the APP_URL in the environment config is also set to http://staging-site-example.com/project/htdocs
Say for example: Route::get('/my-route', 'Controller@test')->name('test-route');
If I use the Route helper function in, say, a template like {{ route('test-route') }}
I get something like http://staging-site-example.com/my-route
rather than http://staging-site-example.com/project/htdocs/my-route
.
When checking out the route helper function in src/Core/Helper.php there is the third parameter you would expect, absolute, which defaults to true. However this value is not passed in to the url('app')->route()
function, instead false is always passed in.
function route($name, $parameters = [], $absolute = true)
{
$path = app('url')->route($name, $parameters, false);
return ($absolute) ? rootUrl($path) : $path;
}
If absolute is passed in as true to the helper function, the path is run through the rootUrl
function, but all this does is prepends the $request->getSchemeAndHttpHost()
which would not take in to account the full App Url, as detailed above.
Apologies if this is some intentional behaviour, but this doesn't seem, to me at least, in line with Laravel!
Thanks! Chris
Thanks for reporting this, we'll look at this. I think there is already a similar issue regarding the management of the absolute URL with the helper function.
The original helper function from Laravel does not use the rootUrl()
function: https://github.com/laravel/framework/blob/8.x/src/Illuminate/Foundation/helpers.php#L697
That might be the issue.