首先,先上效果图吧:
安装captcha:
composer require mews/captcha
发现5.5真的很方便,直接require包就可以了,作为LTS版,强烈建议大家用5.5.
配置验证效果:
在config/captcha.php中有相关的配置,例如长宽,flat配置等,个人觉得使用默认配置吧,也没什么问题。
使用验证码:
分为两个方面,前端展示验证码,后端验证验证码。
前:
<div class="form-group{{ $errors->has('captcha') ? ' has-error' : '' }} code">
<label for="captcha" class="col-md-4 control-label">验证码</label> <div
class="col-md-6"> <input class="form-control tt-text" name="captcha" required>
{!! captcha_img() !!} @if ($errors->has('captcha')) <span class="help-block">
<strong>{{ $errors->first('captcha') }}</strong> </span> @endif </div> </div>
后:
$this->validate($request, [ 'captcha' => 'required|captcha' ]);
当然,你也可以获取captcha之后进行表单验证,具体看文档
<https://laravel-china.org/docs/laravel/5.5/validation/1302>吧。
热门工具 换一换