Laravel Request getting current path with query string

PhpLaravelLaravel 5Laravel Request

Php Problem Overview


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.

Php Solutions


Solution 1 - Php

Try to use the following:

\Request::getRequestUri()

Solution 2 - Php

Laravel 4.5

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()

Laravel >5.1

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()

Solution 3 - Php

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()) : '');

Solution 4 - Php

Get the current URL including the query string.

echo url()->full();

Solution 5 - Php

$request->fullUrl() will also work if you are injecting Illumitate\Http\Request.

Solution 6 - Php

If you have access to the Request $request object you can also use the non static method

$request->getRequestUri()

Solution 7 - Php

The simplest I found is this one:

$request->getPathInfo()

Solution 8 - Php

Get the flag parameter from the URL string http://cube.wisercapital.com/hf/create?flag=1

public function create(Request $request)
{
$flag = $request->input('flag');
return view('hf.create', compact('page_title', 'page_description', 'flag'));
}

Solution 9 - Php

public functin func_name(Request $request){$reqOutput = $request->getRequestUri();}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJohn BupitView Question on Stackoverflow
Solution 1 - PhpHubert DziubińskiView Answer on Stackoverflow
Solution 2 - PhpThomas BolanderView Answer on Stackoverflow
Solution 3 - Phpjedrzej.kuryloView Answer on Stackoverflow
Solution 4 - PhpGr BrainstormView Answer on Stackoverflow
Solution 5 - PhpYadaView Answer on Stackoverflow
Solution 6 - PhpGarrick CrouchView Answer on Stackoverflow
Solution 7 - PhpLeonardo WebsterView Answer on Stackoverflow
Solution 8 - PhpAjaiView Answer on Stackoverflow
Solution 9 - PhpInduView Answer on Stackoverflow