souravmsh/easy-captcha 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

souravmsh/easy-captcha

最新稳定版本:1.2.0

Composer 安装命令:

composer require souravmsh/easy-captcha

包简介

A pure image-based CAPTCHA package for Laravel

README 文档

README

Latest Version on Packagist Total Downloads Software License

An easy, lightweight, pure image-based CAPTCHA package for Laravel (Requires ext-gd). No third-party APIs needed for local generation. The CAPTCHA generates standard image data dynamically directly via PHP. Also supports Google reCAPTCHA v2/v3 and Cloudflare Turnstile (Latest!).

View Landing Page & Documentation

Installation

composer require souravmsh/easy-captcha

The package is auto-discovered by Laravel. If auto-discovery is disabled, register the service provider manually (optional):

Laravel 11+ — in bootstrap/providers.php:

return [
    // ...
    Souravmsh\EasyCaptcha\EasyCaptchaServiceProvider::class,
];

Laravel 7–10 — in config/app.php under providers:

'providers' => [
    // ...
    Souravmsh\EasyCaptcha\EasyCaptchaServiceProvider::class,
],

Configuration

Optionally publish the configuration file to customize CAPTCHA sizes and colors:

php artisan vendor:publish --tag=easy-captcha-config

To overwrite an already published config:

php artisan vendor:publish --tag=easy-captcha-config --force

You can change the CAPTCHA type in config/easy_captcha.php, or easily turn the CAPTCHA off completely for local development/testing using your .env file:

EASY_CAPTCHA_ENABLED=false
EASY_CAPTCHA_TYPE=math
EASY_CAPTCHA_FONT_PATH=UbuntuMono-Regular

Bundled Fonts (Latest!)

The package now comes with built-in fonts that you can use by name in your .env or config:

  • IndieFlower (Default - Handwritten)
  • SpecialElite (Typewriter style)
  • CourierPrime (Monospace)
  • Ubuntu-Bold
  • UbuntuMono-Regular
  • Ubuntu-Italic

Supported types:

  • 'random' (Alphanumeric)
  • 'math' (e.g., 5 + 3, validation checks for 8)
  • 'alphabet' (Letters only)
  • 'number' (Numbers only)
  • 'google' (Google reCAPTCHA v2/v3 support!)
  • 'turnstile' (Cloudflare Turnstile support! - Latest)

Setting up Google reCAPTCHA

If you choose google as the CAPTCHA type, our blade directive and validation facade will automatically hook into Google's APIs. If you want to use older version like v3 then spefify in config file, default is v3. Add your site/secret keys inside the .env:

EASY_CAPTCHA_TYPE=google
EASY_CAPTCHA_GOOGLE_API_VERSION=3 
EASY_CAPTCHA_GOOGLE_SITE_KEY=your-site-key-here
EASY_CAPTCHA_GOOGLE_SECRET_KEY=your-secret-key-here

Setting up Cloudflare Turnstile (Latest!)

If you choose turnstile as the CAPTCHA type, our blade directive and validation facade will automatically hook into Cloudflare's APIs. Add your site/secret keys inside the .env:

EASY_CAPTCHA_TYPE=turnstile
EASY_CAPTCHA_TURNSTILE_SITE_KEY=your-site-key-here
EASY_CAPTCHA_TURNSTILE_SECRET_KEY=your-secret-key-here

Usage

Displaying the CAPTCHA image

In your Blade form, you can render an image tag manually:

@easyCaptcha

This simple blade directive handles showing the <img /> and attaching a neat [Reload] button next to it!

Or you can use the Facade manually if you need more control:

{!! \Souravmsh\EasyCaptcha\Facades\EasyCaptcha::img(['class' => 'my-captcha-class']) !!}

Validating the CAPTCHA

Once the form is submitted, validate the user's input:

use Illuminate\Http\Request;
use Souravmsh\EasyCaptcha\Rules\Captcha;

public function submit(Request $request) {
    // Option 1: String rule (Standard)
    $request->validate([
        'captcha' => 'required|easyCaptcha'
    ]);

    // Option 2: Class-based rule (More robust)
    $request->validate([
        'captcha' => ['required', new Captcha]
    ]);

    // Option 3: Alias rule (More robust)
    $request->validate([
        'captcha' => 'required|captcha'
    ]);

    // Option 4: Alias rule (More robust)
    $request->validate([
        'captcha' => 'required|easy_captcha'
    ]);

    // Success! 
    return "Valid CAPTCHA!";
}

Support

Laravel versions 7, 8, 9, 10, 11, 12, 13 are fully supported. PHP 7.2.5+ & 8.0+ are required along with ext-gd.

统计信息

  • 总下载量: 32
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固