mrlks/cloudflare-turnstile-laravel
Composer 安装命令:
composer require mrlks/cloudflare-turnstile-laravel
包简介
Laravel integration for Cloudflare Turnstile CAPTCHA
README 文档
README
A Laravel package that provides an elegant way to integrate Cloudflare Turnstile CAPTCHA protection into your Laravel applications. Turnstile is Cloudflare's privacy-first CAPTCHA alternative that helps protect your forms from spam and abuse.
Features
- 🚀 Easy integration with Laravel forms
- 🛡️ Middleware for route protection
- ⚡ Simple validation rules
- 🎨 Customizable widget appearance
- 🔧 Configurable settings
Requirements
- PHP ^8.1
- Laravel ^10.0
Installation
You can install the package via composer:
composer require mrlks/cloudflare-turnstile-laravel
Configuration
- Publish the configuration file:
php artisan vendor:publish --provider="MrLks\CloudflareTurnstileLaravel\TurnstileServiceProvider"
- Add your Cloudflare Turnstile credentials to your
.envfile:
TURNSTILE_SITE_KEY=your-site-key TURNSTILE_SECRET_KEY=your-secret-key
Usage
Basic Form Integration
- Add the Turnstile widget to your form:
{!! Turnstile::renderWidget() !!}
- Validate the Turnstile response in your controller:
use MrLks\CloudflareTurnstileLaravel\Rules\TurnstileRule; public function store(Request $request) { $request->validate([ 'cf-turnstile-response' => ['required', new TurnstileRule], ]); // Your logic here }
Using Middleware
Protect your routes using the Turnstile middleware:
// In your routes file Route::post('/protected-route', function () { // Your protected route logic })->middleware('turnstile'); // Or in your controller public function construct() { $this->middleware('turnstile')->only(['store', 'update']); }
Customizing the Widget
You can customize the widget appearance:
{!! Turnstile::renderWidget([ 'data-theme' => 'dark', 'data-size' => 'compact', 'data-action' => 'login', 'data-language' => 'en' ]) !!}
Available options:
- Theme:
light,dark,auto - Size:
normal,compact - Language: Any valid language code
Configuration Options
The config/turnstile.php file allows you to configure:
return [ // Your Cloudflare Turnstile keys 'site_key' => env('TURNSTILE_SITE_KEY', ''), 'secret_key' => env('TURNSTILE_SECRET_KEY', ''), // Verification endpoint 'verify_url' => env('TURNSTILE_VERIFY_URL', 'https://challenges.cloudflare.com/turnstile/v0/siteverify'), // Default widget settings 'theme' => 'light', 'size' => 'normal', ];
Events
The package dispatches the following events:
TurnstileValidated: When a Turnstile challenge is successfully validatedTurnstileFailedValidation: When a Turnstile challenge fails validation
Testing
composer test
Security
If you discover any security-related issues, please email security@example.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Support
For support, please use the issue tracker.
Contributing
Please see CONTRIBUTING.md for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) -
Open a Pull Request
cloudflare-turnstile-laravel
Laravel integration for Cloudflare Turnstile CAPTCHA
1066a7ad2c02e4c3d3d86e8c7d6fba8efae75106
cloudflare-turnstile-laravel
bc520bb64e4deb9561a07f56826d3bd9a264f47c
mrlks/cloudflare-turnstile-laravel 适用场景与选型建议
mrlks/cloudflare-turnstile-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 11 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 mrlks/cloudflare-turnstile-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mrlks/cloudflare-turnstile-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-11-21