发送验证码

一.安装验证码 composer 扩展包#

  1. 安装扩展包:
    composer require mews/captcha
  2. 生成配置文件,并选择 Mews\Captcha\CaptchaServiceProvider 代表的数字回车
    php artisan vendor:publish
  3. 修改 config/captcha.php , 修改 flat 长度为 4 位
  4. 修改注册模板,添加验证码
    <div class="form-group row">
      <label for="captcha" class="col-md-4 col-form-label text-md-right">验证码</label>
          <div class="col-md-6">
             <input id="captcha" class="form-control{{ $errors->has('captcha') ? ' is-invalid' : '' }}" name="captcha" required>
              <img class="thumbnail captcha mt-3 mb-2" src="{{ captcha_src('flat') }}" onclick="this.src='/captcha/flat?'+Math.random()" title="点击图片重新获取验证码">
                 @if ($errors->has('captcha'))
                     <span class="invalid-feedback" role="alert">
                         <strong>{{ $errors->first('captcha') }}</strong>
                        </span>
                    @endif
            </div>
    </div>
  5. 后端添加验证码 captcha 验证
    protected function validator(array $data)
     {
         return Validator::make($data, [
             'name' => ['required', 'string', 'max:255'],
             'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
             'password' => ['required', 'string', 'min:8', 'confirmed'],
             'captcha' => ['required', 'captcha'],
         ], [
             'captcha.required' => '验证码不能为空',
             'captcha.captcha' => '请输入正确的验证码',
         ]);
     }
  6. 预览效果

Laravel

《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

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