无法从流明的发布/发布请求中获取Json

时间:2019-01-31 23:03:46

标签: php json api lumen

我正在尝试在流明中构建一个简单的api,直到我更新了composer程序包,一切都工作正常。现在我无法从任何请求中获得Json。

private $request;

public function __construct(Request $request) {
    $this->request = $request;
}

protected function jwt(User $user) {
    $payload = [
        'iss' => "lumen-jwt", // Issuer of the token
        'sub' => $user->id, // Subject of the token
        'iat' => time(), // Time when JWT was issued. 
        'exp' => time() + 60*60 // Expiration time
    ];

    return JWT::encode($payload, env('JWT_SECRET'));
} 

public function authenticate(User $user) {

    dd($this->request->content);

    $this->validate($this->request, [
        'email'     => 'required|email',
        'password'  => 'required'
    ]);
    // Find the user by email
    $user = User::where('email', $this->request->input('email'))->first();
    if (!$user) {
        // You wil probably have some sort of helpers or whatever
        // to make sure that you have the same response format for
        // differents kind of responses. But let's return the 
        // below respose for now.
        return response()->json([
            'error' => 'Email does not exist.'
        ], 400);
    }
    // Verify the password and generate the token
    if (Hash::check($this->request->input('password'), $user->password)) {
        return response()->json([
            'token' => $this->jwt($user)
        ], 200);
    }
    // Bad Request response
    return response()->json([
        'error' => 'Email or password is wrong.'
    ], 400);
}

}

在邮递员中执行请求且内容设置为application / json

dd($this->request->content);  // output noting
dd($this->request->json());  // output []
dd($this->request->all());  // no hint of my json here, parameter bag is empty, 

我可以在请求的内容中看到序列化形式的json,但是我无法访问它。

使用x-www-form-data时一切正常。

0 个答案:

没有答案