내 API를 테스트 중이므로 요청을 만들고 싶지만 매개 변수를 사용할 수 없습니다. 내가하는 일은 Hello가 World를 가리키는 param을 추가하는 것이지만, Hello는 그 매개 변수를 가져 오려고 할 때 NULL을 반환합니다. 누락 된 것이 무엇입니까? 코드는 다음과 같습니다.Laravel : 요청에 매개 변수를 추가 할 수 없습니다.
//This is routes.php:
<?php
Route::get('/testapi', '[email protected]');
Route::get('/json/locations', '[email protected]');
?>
//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"}
// 어떻게 "NULL"입니까?
여전히 NULL을 반환합니다./ – Rkey
어떻게 테스트합니까? – Jerodev
방금 붙여 넣은 코드와 똑같은 코드를 사용하여 Request : :: Input으로 가져 오기 :: get – Rkey