Download the PHP package mortogo321/laravel-cloudflare-turnstile without Composer
On this page you can find all versions of the php package mortogo321/laravel-cloudflare-turnstile. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mortogo321/laravel-cloudflare-turnstile
More information about mortogo321/laravel-cloudflare-turnstile
Files in mortogo321/laravel-cloudflare-turnstile
Package laravel-cloudflare-turnstile
Short Description Laravel wrapper package for Cloudflare Turnstile with invisible mode, button disabling, and auto-refresh
License MIT
Homepage https://github.com/mortogo321/laravel-cloudflare-turnstile
Informations about the package laravel-cloudflare-turnstile
Laravel Cloudflare Turnstile
A Laravel wrapper package for Cloudflare Turnstile with invisible mode by default, automatic submit button disabling until verification is complete, and refresh button on failure.
Features
- Invisible Mode by Default: Uses
executeappearance mode for seamless user experience - Auto-disable Submit Button: Automatically disables submit buttons until Turnstile is ready
- Refresh on Failure: Shows a refresh button when verification fails or times out
- Easy Integration: Simple Blade component for quick integration
- Flexible Validation: Multiple validation methods (rule class, validation rule string, manual verification)
- Customizable: Override all settings per widget or globally
- Controller-Friendly: Easy to use in any Laravel controller
Installation
Install the package via Composer:
Publish the configuration file:
Optionally, publish the views if you want to customize them:
Configuration
Add your Cloudflare Turnstile keys to your .env file:
Get your Turnstile keys from: https://dash.cloudflare.com/?to=/:account/turnstile
Configuration Options
The package provides several configuration options in config/turnstile.php:
site_key: Your Turnstile site keysecret_key: Your Turnstile secret keyappearance: Widget appearance mode (always,execute,interaction-only) - default:executetheme: Widget theme (light,dark,auto) - default:autosize: Widget size (normal,compact) - default:normallanguage: Widget language (default:auto)retry: Retry behavior (auto,never) - default:autoretry_interval: Time between retries in milliseconds - default:8000timeout: Verification timeout in seconds - default:30show_refresh_button: Show refresh button on failure - default:truedisable_submit_until_ready: Disable submit button until ready - default:true
Usage
Basic Usage in Blade Views
Add the Turnstile widget to your form:
Controller Validation
Option 1: Using the Validation Rule Class (Recommended)
Option 2: Using the String Validation Rule
Option 3: Manual Verification with Facade
Option 4: Manual Verification with Service
Customizing the Widget
You can customize the widget behavior using component attributes:
Custom Submit Button Selector
By default, the package looks for buttons with the data-turnstile-button attribute. You can customize this:
Displaying Validation Errors
Display validation errors in your Blade views:
How It Works
- Widget Loading: The Turnstile widget loads in invisible mode (
executeappearance) - Button Disabling: Submit buttons with
data-turnstile-buttonattribute are automatically disabled - Verification: Turnstile runs automatically when the form is ready
- Button Enabling: Once verification succeeds, submit buttons are re-enabled
- Refresh on Failure: If verification fails or times out, a refresh button appears
- Form Submission: The form submits with the
cf-turnstile-responsetoken - Server Validation: Your controller validates the token with Cloudflare
API Reference
TurnstileService Methods
Verification Response
The verify() method returns an array with the following structure:
Testing
For testing purposes, you can use Cloudflare's test keys:
- Site Key:
1x00000000000000000000AA(Always passes) - Site Key:
2x00000000000000000000AB(Always blocks) - Site Key:
3x00000000000000000000FF(Forces interactive challenge)
Troubleshooting
Submit button remains disabled
- Ensure your button has the
data-turnstile-buttonattribute or matches your custom selector - Check browser console for JavaScript errors
- Verify your site key is correct
Verification fails in controller
- Ensure the
cf-turnstile-responsefield is present in the request - Verify your secret key is correct in
.env - Check that the token hasn't expired (tokens are valid for a limited time)
Widget doesn't appear
- Check that your site key is set in
.env - Verify the Cloudflare Turnstile script is loading (check browser network tab)
- Check browser console for errors
Security
- Never expose your secret key in client-side code
- Always validate on the server side
- Tokens can only be used once and expire after a short time
- Consider rate limiting your forms for additional protection
License
MIT License
Credits
- Cloudflare Turnstile
- Built for Laravel
Support
For issues, questions, or contributions, please visit the GitHub repository.
All versions of laravel-cloudflare-turnstile with dependencies
illuminate/support Version ^10.0|^11.0
illuminate/validation Version ^10.0|^11.0
guzzlehttp/guzzle Version ^7.0