定制 straylightagency/laravel-captcha 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱: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).

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固