laravel5.7验证码并验证登录
跑验证码第三方包
composer require mews/captcha
在config/app.php
进行配置
‘providers’ => [
// …
Mews\Captcha\CaptchaServiceProvider::class,
]
‘aliases’ => [
// …
‘Captcha’ => Mews\Captcha\Facades\Captcha::class,
]
跑命令 php artisan vendor:publish
进行自定义验证码规则
前端使用
<div class="am-form-group">
<label>验证码:</label>
<input type="text" class="tpl-form-input" name="captcha" placeholder="请输入验证码">
<div style="margin-left: 10px;">
<img src="{
{ captcha_src('flat') }}" style="cursor: pointer" onclick="this.src='{
{captcha_src('flat')}}&'+Math.random()" >//captcha_src('flat')是应用flat规则不填为默认
</div>
</div>
后台验证
protected function validateLogin(Request $request)
{
$request->validate([
'captcha' => 'required|captcha',
$this->username() => 'required|string',
'password' => 'required|string',
]);
}
还没有评论,来说两句吧...