[英]Laravel \Request::get()
Is there a way to check if any GET variables exist? 有没有办法检查是否存在任何GET变量? I'm not trying to find a particular GET variable I need to create an if statement if ANY get variable exists. 我不是要查找特定的GET变量,如果存在任何get变量,则需要创建一个if语句。
For example, I have a route 例如,我有一条路线
/product /产品
If for any reason someone adds variables to the end of the route I'd like to include a canonical link in the header of the page. 如果由于某种原因有人在路由的末尾添加了变量,我想在页面标题中添加一个规范链接。
<link rel="canonical" href="{{ url($page->slug) }}" />
I can apply this canonical link if I know the parameter. 如果知道参数,则可以应用此规范链接。 For example if some one adds 例如,如果有人添加
/product?model=1 /产品?模型= 1
However if someone adds a get variable I'm unaware of then this wouldn't include the link. 但是,如果有人添加了我不知道的get变量,则该链接将不包含该链接。
I've tried 我试过了
@if(/Request::get())
<link rel="canonical" href="{{ url($page->slug) }}" />
@endif
However this squawks with 但是这与
Too few arguments to function 实参太少
You can use \\Request::query()
to get url params in laravel blade 您可以使用\\Request::query()
获取laravel刀片中的网址参数
Try to check all params with this 尝试与此检查所有参数
<?php print_r(\Request::query()); ?>
And apply this code to check any param exist in url 并应用此代码来检查url中是否存在任何参数
@if(\Request::query())
Check details in laravel doc 在laravel文档中查看详细信息
I managed to do this by counting $_GET . 我通过计数$ _GET来做到这一点。 for example: 例如:
@if(count($_GET) > 0)
<link rel="canonical" href="{{ Request::url() }}" />
@endif
If you want to check url contains params or not, then you can use this- 如果您要检查网址是否包含参数,则可以使用此-
if($request->input()){
///do your task
}
And in blade check like- 并在刀片中检查-
@if(\Request::input())
@endif
or if you want to get all keys then use $key => $value notation in foreach : 或者,如果要获取所有键,请在foreach中使用$ key => $ value表示法:
$keys = array();
foreach ($request->input() as $key => $part) {
$keys[] = $key;
}
$keys will contain all parameter or input field $ keys将包含所有参数或输入字段
只需通过Input::get()
获取所有$ _GET变量:
$parameters= \Input::get()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.