为什么 Laravel REST 控制器 $request->input 为 NULL?

Tom*_*omR 5 php rest laravel laravel-5.2

我正在关注教程http://www.tutorials.kode-blog.com/laravel-5-angularjs-tutorial并且我设法为我的控制器编写了类似的方法:

public function update(Request $request, $id) {
    $employee = Employee::find($id);

    $employee->name = $request->input('name');
    //...
    $employee->save();

    return "Sucess updating user #" . $employee->id;
}
Run Code Online (Sandbox Code Playgroud)

在教程中认为此代码有效,但实际上 var_dump($request->input) 给出了 NULL。那么 - 我应该使用什么 $request 变量来获取请求的正文?我做了 var_dump($request) 但结构太大了。实际上,我对本教程持怀疑态度 -我们真的需要列出标准更新程序中的所有字段吗?

swa*_*ins 4

您可以通过以下方式访问输入数据:

$input = $request->all();
Run Code Online (Sandbox Code Playgroud)

https://laravel.com/docs/5.2/requests#retriving-input

$http但是,在使用 AngularJS模块时,我也必须以这种方式获取输入:

$input = file_get_contents('php://input');
Run Code Online (Sandbox Code Playgroud)