
首先,登录网址 packagist.org 查找 laravel captcha,找到mews/captcha ,根据 packagist 上的使用方法一步步来实现验证码的安装。
composer 安装:composer require mews/captcha

注册providers (config/app.php) ,在这个数组中的最后追加如下代码:
Mews\Captcha\CaptchaServiceProvider::class,
注册aliases (config/app.php),在这个数组中的最后追加如下代码:
'Captcha' => Mews\Captcha\Facades\Captcha::class,
生成配置文件,在 Composer 命令行中输入如下命令:
php artisan vendor:publish

进入config/captcha.php 文件,修改default 数组 可以对验证码进行样式、数量、大小上的修改。

页面中使用:
<img src="{{captcha_src()}}" style="cursor: pointer" onclick="this.src='{{captcha_src()}}'+Math.random()" style="width: 50%; float: right">
@if ($errors->any())
    <div class="alert">
        @foreach ($errors->all() as $error)
            {{ $error }}
        @endforeach
    </div>
@endif方法中验证验证码;
<?php
 public function dologin(Request $request){
        $validatedData = $request->validate([
            'captcha' => 'required|captcha',
        ],[
            'captcha.required' => '验证码不能为空',
            'captcha.captcha' => '验证码错误',
        ]);
 }
 ?>注:若出现composer无法安装验证码,可以参考这篇文章,/adetail/274.html