Laravel Request getting current path with query st

2019-03-09 17:26发布

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.

8条回答
小情绪 Triste *
2楼-- · 2019-03-09 17:55
public functin func_name(Request $request){$reqOutput = $request->getRequestUri();}
查看更多
家丑人穷心不美
3楼-- · 2019-03-09 18:00

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()
查看更多
Viruses.
4楼-- · 2019-03-09 18:11

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'));
}
查看更多
萌系小妹纸
5楼-- · 2019-03-09 18:12

Try to use the following:

\Request::getRequestUri()
查看更多
狗以群分
6楼-- · 2019-03-09 18:13

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

查看更多
做个烂人
7楼-- · 2019-03-09 18:14

Get the current URL including the query string.

echo url()->full();
查看更多
登录 后发表回答