afromansr / laravel-math-captcha
基于 Laravel 框架的数学验证码包
v1.0
2020-10-01 00:57 UTC
Requires
- php: >=5.6
Requires (Dev)
- orchestra/testbench: ^6.2
This package is auto-updated.
Last update: 2024-09-29 06:08:54 UTC
README
基于 Laravel Simple Captcha 的简单数学验证码
验证码是防止表单提交垃圾邮件最常用的技术。Laravel Math Captcha 包可以帮助您防止垃圾邮件表单提交。这是一个真正简单且轻量级的 Laravel 验证码包。
Laravel Math Captcha 的特性
- 轻量级
- 简单易用
- 支持 Laravel 5, 6
- 验证码验证规则
- 可定制的数学运算
安装
使用 [Composer] 安装包
$ composer require afromansr/laravel-math-captcha
使用方法
使用 getCaptchaBox
方法,在需要添加验证码的表单中使用。
{!!getCaptchaBox()!!}
可选:您可以更改验证码答案输入框的名称。默认值为 _answer
{!!getCaptchaBox('txtAnswer')!!}
示例
<form action="#" method="POST"> @csrf <div class="form-group"> <label for="name">Name</label> <input type="text" class="form-control"> </div> <div class="form-group"> <label for="email">E-mail</label> <input type="text" class="form-control"> </div> <div class="form-group"> {!!getCaptchaBox()!!} </div> <button class="btn btn-sm btn-default">Submit</button> </form>
自定义验证码框
为了调整您的 HTML 中的验证码框,您可以使用 getCaptchaQuestion
方法来创建验证码框。
<p>Captcha</p> <p>{{getCaptchaQuestion()}}</p> <input name="_answer" type="number">
自定义验证码数学运算
默认情况下,验证码将自动生成带有随机数学运算符(加法、减法或乘法)的数学问题。要自定义此设置,您需要发布配置文件。
$ php artisan vendor:publish --tag=captcha-config
验证
在处理请求时使用 math_captcha
验证规则。
public function handleForm(Request $request) { $this->validate( $request, [ '_answer'=>'required|simple_captcha' ]); }