Php Laravel 5请求值为空
这是我的控制器中的代码:Php Laravel 5请求值为空,php,laravel,post,laravel-5,request,Php,Laravel,Post,Laravel 5,Request,这是我的控制器中的代码: public function postExample(Request $request) { $id = $request->input('subjectId'); Log::warning('id is:' . $id . ",and request:" . $request); 问题是变量$id为null(空字符串)。以下是日志: id is:,and request:POST .... Accept
public function postExample(Request $request) {
$id = $request->input('subjectId');
Log::warning('id is:' . $id . ",and request:" . $request);
问题是变量$id为null(空字符串)。以下是日志:
id is:,and request:POST ....
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate
Content-Length: 19
Content-Type: application/x-www-form-urlencoded
. . . .
{"subjectId":"13"}
我试过:$id=$request->get('subjectId')代码>和它是一样的
编辑:我正在使用angularjs发布,代码如下:
$http({
method: 'POST',
url: '/api/profesor/setStrukturaPredmeta',
data: { subjectId: '13' },
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).then(function successCallback(response) {
$("body").html(JSON.stringify(response));
}, function errorCallback(response) {
$("body").html("error: "+JSON.stringify(response));
});
我通过删除angularjs控制器中的头文件解决了这个问题,但我不明白为什么在包含头文件时它不起作用 你是如何定义你的路线的?你是指我的routes.php文件中的路线吗?我可以编辑文章,如果这是你的意思?我不认为它是相关的,因为响应对象中的数据包含我想要的数据,而且我确信客户端调用正在命中我的函数,因为日志文件正在更新;只需删除postExample
上的前缀post
,它将保留为隐式route@PeteHouston我不知道这一点,但这不是问题所在,因为我在为这篇文章翻译我的母语代码,它被称为其他东西,但我在其中有“set”一词。我编辑了。@craig_h我编辑了我的问题。是的,同样的问题。。。Idk这怎么行啊,哈哈!