令牌中的PHP-JWT用户

时间:2018-02-20 11:16:46

标签: php laravel jwt lumen

在我的php api(框架流明)中,我正在检索用户数据和令牌。 我想将此用户数据放入哈希标记。

我目前的代码如下:

    if (! $token = $this->jwt->attempt($request->only('email', 'password'))) {
        return response()->json(['user_not_found'], 404);
    }

    $user = $this->jwt->user();

    return response()->json(compact('token', 'user'));

1 个答案:

答案 0 :(得分:1)

您可以像这样使用散列数据

                   $key= "User access token";                  // create a key

                    $hash_data= array(
                    "email" => $email,
                    "password" => $password,
                );

               $access_token = JWT::encode($hash_data, $key);
               return response()->json(compact('token', 'access_token '));

$ access_token 详细信息将采用 加密 格式,只需解码时