简体   繁体   English

Laravel GET请求结果中带有附加的“?” 字符

[英]Laravel GET request results with an additional '?' character

I'm getting a weird bug in Laravel while using a GET request. 使用GET请求时,我在Laravel中遇到了一个奇怪的错误。 I'm performing a get request via javascript like so: 我正在通过javascript执行获取请求,如下所示:

window.location = "messages/clone?id=" + anchorID + '&name=' + newMessageName;

And I'm using a dd($request) right away inside the controller. 我正在控制器内部立即使用dd($request) The desired behavior would be 所需的行为是

Request->request->parameters: array:2[
'id' => 'value'
'name' => 'value'
]

Yet I'm having this output: 但是我有这个输出:

Request->request->parameters: array:2[
'?id' => 'value'
'name' => 'value'
]

You'll notice that there's an extra '?' 您会注意到还有一个额外的“?” sign right before the 'id'. 在“ id”之前签名。 I'm wondering what's the cause of this? 我想知道这是什么原因?

Thanks in advance, Alex 预先感谢Alex

The parameters that you are dumping are arguments of Route::get() method. 您要转储的参数是Route::get()方法的参数。 '?'`s mean is the parameter is nullable. “?”的意思是参数可以为空。

If you want to access get parameters you should use: 如果要访问get参数,则应使用:

$request->query('id');

read more here : https://laravel.com/docs/5.8/requests 在此处阅读更多信息: https : //laravel.com/docs/5.8/requests

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM