php Laravel 请求使用查询字符串获取当前路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31555494/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Request getting current path with query string
提问by John Bupit
Is there a Laravel way to get the current path of a Request with its query parameters?
有没有 Laravel 方法来获取请求的当前路径及其查询参数?
For instance, for the URL:
例如,对于 URL:
http://www.example.com/one/two?key=value
Request::getPathInfo()
would return /one/two
.
Request::getPathInfo()
会回来/one/two
。
Request::url()
would return http://www.example.com/one/two
.
Request::url()
会回来http://www.example.com/one/two
。
The desired output is /one/two?key=value
.
所需的输出是/one/two?key=value
。
采纳答案by Hubert Dziubiński
Try to use the following:
尝试使用以下内容:
\Request::getRequestUri()
回答by Thomas Bolander
Laravel 4.5
Laravel 4.5
Just use
只需使用
Request::fullUrl()
It will return the full url
它将返回完整的 url
You can extract the Querystring with str_replace
您可以使用 str_replace 提取查询字符串
str_replace(Request::url(), '', Request::fullUrl())
Or you can get a array of all the queries with
或者您可以获得所有查询的数组
Request::query()
Laravel >5.1
Laravel >5.1
Just use
只需使用
$request->fullUrl()
It will return the full url
它将返回完整的 url
You can extract the Querystring with str_replace
您可以使用 str_replace 提取查询字符串
str_replace($request->url(), '',$request->fullUrl())
Or you can get a array of all the queries with
或者您可以获得所有查询的数组
$request->query()
回答by jedrzej.kurylo
Requestclass 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:
Request类不提供可以准确返回您需要的内容的方法。但是您可以通过连接其他两种方法的结果轻松获得它:
echo (Request::getPathInfo() . (Request::getQueryString() ? ('?' . Request::getQueryString()) : '');
回答by Gr Brainstorm
Get the current URL including the query string.
获取包含查询字符串的当前 URL。
echo url()->full();
回答by Yada
$request->fullUrl()
will also work if you are injecting Illumitate\Http\Request
.
$request->fullUrl()
如果您正在注射,也将起作用Illumitate\Http\Request
。
回答by Ajai
Get the flag parameter from the URL string http://cube.wisercapital.com/hf/create?flag=1
从 URL 字符串中获取标志参数 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'));
}
回答by Braden Holt
Similar to Yada's answer: $request->url() will also work if you are injecting Illuminate\Http\Request
类似于 Yada 的回答:如果您正在注入 Illuminate\Http\Request,$request->url() 也将起作用
Edit: The difference between fullUrl and url is the fullUrl includes your query parameters
编辑:fullUrl 和 url 之间的区别是 fullUrl 包含您的查询参数
回答by Indu
public functin func_name(Request $request){$reqOutput = $request->getRequestUri();}