Request validate 验证完毕怎么执行自定义事件

        $validated = $request->validated(); //这里如果验证失败了我想执行自定义事件
        if ($this->hasTooManyLoginAttempts($request)) {
//            $errorNum = $this->limiter()->attempts($this->throttleKey($request));
//            $request->setFormat(['errorNum'=>$errorNum]);
            $validator = $request->validate( [
                'captcha' => 'required',
            ]); //这里也是,如果验证失败了我想执行自定义事件
        }
        $LoginResult = User::UserLogin($request);

        if ($LoginResult['status'] &&$LoginResult['user']) {
            if ($LoginResult['user'] instanceof User) {
                $this->clearLoginAttempts($request);
                return $this->JsonReturn(
                    [
                        'token' => $LoginResult['user']->createToken('token')->plainTextToken
                    ]
                );
            }
        } else {
            $this->incrementLoginAttempts($request);
            $errorNum = $this->limiter()->attempts($this->throttleKey($request));
            return $this->JsonError($LoginResult['msg']."___".$errorNum);
        }

在登陆过程当中,我判断了用户的错误次数(包括了验证错误次数),因为客户端需要通过错误次数判断是否显示验证码,遇到一个问题就是如何在Request验证过后添加一个事件去执行我的逻辑(增加错误次数,错误信息追加用户错误次数)

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
最佳答案

file 看这个是否符合你的需求

6年前 评论
sandbox (楼主) 6年前
讨论数量: 2

file 看这个是否符合你的需求

6年前 评论
sandbox (楼主) 6年前

验证之后的钩子,添加自己的逻辑
表单验证《Laravel 7 中文文档》 file

6年前 评论
sandbox (楼主) 6年前
lddtime (作者) 6年前
sandbox (楼主) 6年前

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