大家有没有遇到这个问题,是我少了哪个步骤吗?

完全按照教程写的,就是获取不到token,不知道哪里出了问题?

public function store(AuthorizationRequest $request)
    {
        $username = $request->username;

        filter_var($username, FILTER_VALIDATE_EMAIL) ?
            $credentials['email'] = $username :
            $credentials['phone'] = $username;

        $credentials['password'] = $request->password;

        if (!$token = \Auth::guard('api')->attempt($credentials)) {
            throw new AuthenticationException('用户名或密码错误');
        }

        return response()->json([
            'access_token' => $token,
            'token_type'   => 'Bearer',
            'expires_in'   => \Auth::guard('api')->factory()->getTTL() * 60,
        ])->setStatusCode(201);
    }

Postman报错如下图:

在tinker中虽然能获得token,但是会有错误警告

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
最佳答案

已解决
1.移除安装包 composer remove tymon/jwt-auth
2.composer.json 添加require 中添加"tymon/jwt-auth": "^1.0"
3.更新安装包composer update
4.重新生成jwt的secret art jwt:secret

3年前 评论
讨论数量: 1

已解决
1.移除安装包 composer remove tymon/jwt-auth
2.composer.json 添加require 中添加"tymon/jwt-auth": "^1.0"
3.更新安装包composer update
4.重新生成jwt的secret art jwt:secret

3年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!