如何修改laravel sanctum 令牌验证 未登录返回的响应

laravel sanctum 令牌验证 未登录返回的响应:
状态码 401

{
    "message": "Unauthenticated."
}

我想知道这个响应怎么修改或配置
希望看到的大神指点一二

《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
最佳答案

在 namespace App\Exceptions\Handler;加入下面代码 public function register() {

    $this->renderable(function (\Illuminate\Auth\AuthenticationException $e, $request) {
        return response()->json([
            'error_code' => 401,
            'data' => (object) [],
            'error_data' => (object) [],
            'message' => 'Unauthenticated'
        ], 401);
    });
}
4年前 评论
Ahmatjan 3年前
讨论数量: 5

佬大的这篇教程可以参考下!

https://learnku.com/laravel/t/43077

4年前 评论

在 namespace App\Exceptions\Handler;加入下面代码 public function register() {

    $this->renderable(function (\Illuminate\Auth\AuthenticationException $e, $request) {
        return response()->json([
            'error_code' => 401,
            'data' => (object) [],
            'error_data' => (object) [],
            'message' => 'Unauthenticated'
        ], 401);
    });
}
4年前 评论
Ahmatjan 3年前
chowjiawei
public function report(Throwable $exception)
    {
        if ($exception instanceof AuthenticationException) {
            if ($exception->getMessage()=='Unauthenticated.') {
                throw new UnauthorizedHttpException('Unauthenticated', "账号未登录,请前往登录");
            }
        }

        parent::report($exception);
    }
4年前 评论
chowjiawei (作者) 4年前

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