Is there a Laravel way to get the current path of a Request with its query parameters?
For instance, for the URL:
http://www.example.com/one/two?key=value
Request::getPathInfo()
would return /one/two
.
Request::url()
would return http://www.example.com/one/two
.
The desired output is /one/two?key=value
.
Try to use the following:
\Request::getRequestUri()
Just use
Request::fullUrl()
It will return the full url
You can extract the Querystring with str_replace
str_replace(Request::url(), '', Request::fullUrl())
Or you can get a array of all the queries with
Request::query()
Just use
$request->fullUrl()
It will return the full url
You can extract the Querystring with str_replace
str_replace($request->url(), '',$request->fullUrl())
Or you can get a array of all the queries with
$request->query()
Request class doesn't offer a method that would return exactly what you need. But you can easily get it by concatenating results of 2 other methods:
echo (Request::getPathInfo() . (Request::getQueryString() ? ('?' . Request::getQueryString()) : '');
Get the current URL including the query string.
echo url()->full();
$request->fullUrl()
will also work if you are injecting Illumitate\Http\Request
.
If you have access to the Request $request
object you can also use the non static method
$request->getRequestUri()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With