straylightagency/laravel-captcha 问题修复 & 功能扩展

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

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

straylightagency/laravel-captcha

Composer 安装命令:

composer require straylightagency/laravel-captcha

包简介

Laravel package with prepared drivers to enable captcha services like Google Recaptcha or Cloudflare Turnstile using Validator Rules.

README 文档

README

Adds Captcha verification functionality to Laravel based on services API.

Installation

Require this package with composer.

composer require straylightagency/laravel-captcha

Laravel without auto-discovery:

If you do not use auto-discovery, add the ServiceProvider to the providers array in bootstrap/providers.php :

\Straylightagency\LaravelCaptcha\CaptchaServiceProvider::class,

Use this artisan command to publish the captcha.php file inside your config folder :

php artisan vendor:publish --tag=captcha

You must set the site key and secret key based on the service you want to use inside your .env file :

## select your drive here : fake, recaptcha, recaptcha_enterprise or turnstile
CAPTCHA_DRIVER=recaptcha_enterprise

## if you use Google ReCaptcha or ReCaptcha Enterprise :
GOOGLE_RECAPTCHA_SITE_KEY="FAK3S1T3K3Y21AI3C9S3VJZ-V65M1SMWLGEPX4SB"
GOOGLE_RECAPTCHA_API_KEY="FAK3AP1K3YXEFG7V2EV1HK1-RGGGU817475938X1O0"
GOOGLE_RECAPTCHA_PROJECT_ID="project-123456"
GOOGLE_RECAPTCHA_SECRET_KEY="FAK3S3CR3TK3YBQYVMJQYMLT4W57RTFFO0MF38VB"

## if you use Cloudflare Turnstile :
CLOUDFLARE_TURNSTILE_SITE_KEY="FAK3S1T3K3YNPY1AEHI2O6P-6AYWQVLJ8439LG3N"
CLOUDFLARE_TURNSTILE_SECRET_KEY="FAK3S3CR3TK3Y8X1O0T0Q2KBQWLKEDUQYNP6GHE3"

In your languages directory, add an extra translation in every validation.php language file :

'captcha' => 'The captcha is not valid.',

Validation

You can use the captcha_rule() helper function directly inside the validation array :

$validator = Validator::make( $request->all(), [
    // [...]
    'captcha' => ['required', 'string', captcha_rule()],
] );

You can also use the captcha rule macro :

$validator = Validator::make( $request->all(), [
    // [...]
    'captcha' => ['required|string|captcha'], // works too
] );

Use the ->default() method if you want to use the required and string macro with the captcha rule.

$validator = Validator::make( $request->all(), [
    'name' => ['required', 'string'],
    'email' => ['required', 'string', 'email'],
    'content' => ['required', 'string'],
    ...captcha_rule()->default(), 
    // parameter $key_name of default() method allow you to edit the field name.
] );

Some Verifier needs a script tag inside the <head> tag of your HTML page, you can use an helper function to print the right script based on the selected Verifier :

<head>
    <!-- rest of your head tag -->
    {!! captcha_script() !!}
    <!-- rest of your head tag -->
</head>

For more information about frontend integration, check the documentation bellow from the API service you want to use.

Requirement

PHP 8.3 or above

See also

Credits

License

The MIT License (MIT).

straylightagency/laravel-captcha 适用场景与选型建议

straylightagency/laravel-captcha 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 05 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「recaptcha」 「captcha」 「turnstile」 「recaptcha-enterprise」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 straylightagency/laravel-captcha 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 straylightagency/laravel-captcha 我们能提供哪些服务?
定制开发 / 二次开发

基于 straylightagency/laravel-captcha 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-09