使用流明的简单POST

时间:2016-07-16 10:47:00

标签: php post lumen

我在routes.php中有以下方法:

$app->post('insertGender', function ($NAME) {
        $result = DB::insert("INSERT INTO HK_GENDER (NAME) VALUES (?)",[$NAME]);
        return ($result)? "wow":"Noo";
    });

我尝试使用Postman通过表单传递参数 enter image description here 我收到错误

Missing argument 1 for Closure::{closure}()
in routes.php line 93
at Application->Laravel\Lumen\Concerns\{closure}('2', 'Missing argument 1 for Closure::{closure}()', '93', array()) in routes.php
at Closure->{closure}()

为什么提供的参数未使用?

1 个答案:

答案 0 :(得分:0)

正确的方法是从请求中获取数据,如下所示:

$app->post('insertGender', function (Illuminate\Http\Request $request) {
        $NAME = $request->input('NAME');
        $result = DB::insert("INSERT INTO HK_GENDER (NAME) VALUES (?)",[$NAME]);
        return ($result)? "wow":"Noo";
    });