当我用Request获取变量时为空

时间:2019-05-16 18:35:29

标签: mysql laravel request

这是我得到的错误:“ SQLSTATE [23000]:违反完整性约束:1048 Le champ'username'ne peutêtrevide(null)(SQL:update user set username =吗? ,pseudo =?,email =?,password =?,其中id = 29)“

public function updateUser($id, Request $request)
{
    if ($id != NULL) {
        $username = $request->get('username');
        $pseudo = $request->get('pseudo');
        $email = $request->get('email');
        $password = $request->get('password');
        $retour = testToken();
        if($retour == TRUE) {
            $data = User::where('id', $id)->update(array('username'=>$username, 'pseudo'=>$pseudo, 'email'=>$email, 'password'=>$password));
            return response()->json([
                'message'=>'OK',
                'data'=>$data]
            ,200);
        } else {
            return response()->json([
                'message'=>'Forbidden',
            ]
            ,403);
        }
    } else {
        return response()->json([
        'message'=>'Not found',
        ]
        ,404);
    }       
}

enter image description here

dd($ request-> input()); 我得到一个空数组:enter image description here

1 个答案:

答案 0 :(得分:0)

好吧,答案就是通过这种方式获取参数:

$username = Input::get('username'); $pseudo = Input::get('pseudo'); $email = Input::get('email'); $password = Input::get('password');