Laravel从网址获取查询 [英] Laravel get queries from url
问题描述
如何从url获取所有查询参数?
How do I get all query parameters from the url?
因此,我们假设网址为:
So let's say the url is:
http://website.com?page=1&?forum=test
我的控制器中需要此部分:
I need this part in my controller:
http://website.com ?page = 1&?forum = test
每个请求的查询参数可以不同.所以Input::get('page');
或Input::get('forum');
并没有帮助,因为我
不知道会发生什么.
the query parameters can be different with every request. So Input::get('page');
or Input::get('forum');
does not help because I
don't know what to can expect.
已经查看了 docs ,但找不到.
Already looked at the docs but I can't find it.
谢谢
推荐答案
您可以使用
$params = $request->query->all();
有关请求对象的更多信息,可以在 Symfony的请求中找到文档页面.
More information about the request object can be found at the Symfony's Request documentation page.
这是一种推荐的访问请求数据的方法,永远不要依赖诸如_GET
之类的超全局数组.
This is a recommended way of accessing Request data, never rely on Superglobal arrays like _GET
and such.
这篇关于Laravel从网址获取查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!