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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 straylightagency/laravel-captcha 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Client library for reCAPTCHA with proxy support, a free service that protects websites from spam and abuse.
Diese Contao 4 Erweiterung stellt Google reCAPTCHA V2 in Form eines neuen Formularfeldes im Formulargenerator bereit. This extension provides Google reCAPTCHA V2 in the form of a new form field in the form generator of Contao Open Source CMS.
A simple and easy to use Google ReCaptcha v3 package for Laravel
Two Captcha
Multi-provider captcha integration for Filament forms (hCaptcha, reCAPTCHA v2/v3, Turnstile)
PHP package for easy integration with solvecaptcha API.
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 48
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-05-09