Php 拉威尔:可以';t向请求添加参数

Php 拉威尔:可以';t向请求添加参数,php,laravel,request,params,Php,Laravel,Request,Params,我正在测试我的API,所以我想创建请求,但我无法让参数工作。我所做的只是添加一个参数,其中Hello指向World,但当我尝试获取该参数时,Hello返回NULL。少了什么?代码如下: //This is routes.php: <?php Route::get('/testapi', 'TestController@testapi'); Route::get('/json/locations', 'APILocationController@getForUser'); ?>

我正在测试我的API,所以我想创建请求,但我无法让参数工作。我所做的只是添加一个参数,其中Hello指向World,但当我尝试获取该参数时,Hello返回NULL。少了什么?代码如下:

//This is routes.php:
<?php 
Route::get('/testapi', 'TestController@testapi');
Route::get('/json/locations', 'APILocationController@getForUser');
?>


//This is TestController.php:
<?php

class TestController extends \BaseController {
    public function testapi() {
        echo 'Create the request';
        echo '<br>';
        $request = Request::create('/json/locations', 'GET', array('Hello' => 'World'));
        return Route::dispatch($request)->getContent();
    }
}
?>


//This is APILocationController.php:
<?php

class APILocationController extends \BaseController {
    public function getForUser() {
        echo var_dump(Request::get('Hello'));
        echo '<br>';
        return Response::json(array('message' => 'Index all locations based on User'), 200);
    }
}
?>

//This is the output:
Create the request
NULL 
{"message":"Index all locations based on User"}
//这是routes.php:
//这是TestController.php:
//这是apLocationController.php:
//这是输出:
创建请求
无效的
{“消息”:“根据用户索引所有位置”}

//“NULL”是什么意思?

要在Laravel中获取get或POST参数,应该使用

添加一个“Request::replace($Request->input());”解决了我的问题,我不知道为什么:

    $request = Request::create('/json/locations', 'GET', array('Hello' => 'World'));
    Request::replace($request->input());
    return Route::dispatch($request)->getContent();

不管怎样,它现在起作用了。忘了更新这里的问题。

仍然返回NULL:/如何测试这个问题?使用我刚才粘贴的完全相同的代码,我只是用Input::getNo替换了Request::get不,您使用什么确切的url或工具来测试请求?/testapi,我们可以看到它,因为输出首先打印了/testapi函数中的“Create the Request”(创建请求),保证创建请求::create('/json/locations',GET',array('Hello'=>'World');
    $request = Request::create('/json/locations', 'GET', array('Hello' => 'World'));
    Request::replace($request->input());
    return Route::dispatch($request)->getContent();