你们怎么在Laravel8中自定义csrf提示的

public function render($request, Exception $exception)
{

    if ($exception instanceof AuthorizationException && request()->ajax()) {
        throw new InvalidRequestException('没有操作权限');
    }

    if ($exception instanceof \Illuminate\Database\Eloquent\ModelNotFoundException && request()->ajax()) {
        if($exception->getModel() == "App\Models\TaskOrder") {
            $response = response()->json(['message'  => '订单已删除'], 404);
            throw new HttpResponseException($response);
        }
    }

    if ($exception instanceof \Illuminate\Session\TokenMismatchException && request()->ajax()) {
        throw new InvalidRequestException('页面过期,请刷新页面 Page expired, please refresh the page');
    }

    return parent::render($request, $exception);
}


这样的代码在Laravel8中不能用了,我现在在升级我的项目,烦的不行
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
讨论数量: 3

尝试一下把最后TokenMismatchException 这个异常写在第一步

4年前 评论

和位置没关系,是在Laravel8中这样的代码没法用了。这个我在5.8中是可以用的

4年前 评论

\app\Http\Middleware\VerifyCsrfToken.php 重写handle方法

2年前 评论

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