Download the PHP package danieledesantis/laravel-cloudflare-turnstile-react-blade without Composer
On this page you can find all versions of the php package danieledesantis/laravel-cloudflare-turnstile-react-blade. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download danieledesantis/laravel-cloudflare-turnstile-react-blade
More information about danieledesantis/laravel-cloudflare-turnstile-react-blade
Files in danieledesantis/laravel-cloudflare-turnstile-react-blade
Package laravel-cloudflare-turnstile-react-blade
Short Description Cloudflare Turnstile integration for Laravel with support for React, Inertia.js and Blade
License MIT
Informations about the package laravel-cloudflare-turnstile-react-blade
Laravel Cloudflare Turnstile for React and Blade
Cloudflare Turnstile integration for Laravel with built-in support for Blade, React, and Inertia.js. Protect your Laravel applications from bots and abuse with Cloudflare's free CAPTCHA alternative.
Quickstart
Read the Quick Start Guide to get up and running in 5 minutes.
Features
- Easy Integration - Drop-in Blade components and React hooks
- Multiple Frameworks - Support for Blade, React and Inertia.js
- Secure - Server-side validation with customizable rules
- Testable - Built-in testing mode for automated tests
- Configurable - Extensive configuration options
- Middleware Support - Protect routes with middleware
- Validation Rules - Custom Laravel validation rules
- IP Whitelisting - Skip verification for trusted IPs
Requirements
- PHP 8.1 or higher
- Laravel 10.x or higher
- A Cloudflare Turnstile site key and secret key
Installation
Step 1: Install via Composer
Step 2: Publish Configuration
Step 3: Publish Components
Publish React/TypeScript Components (for React/Inertia.js projects)
If you are using React or Inertia.js, publish the TypeScript components:
This will publish the components to resources/js/Components/Turnstile/:
hooks/useTurnstile.tsx- React hook for Turnstilecomponents/Turnstile.tsx- React component for Turnstileindex.ts- Exports
You can then import them directly in your code:
Publish Blade Components (for Blade projects)
If you are using the Blade templating engine, publish the component:
This will publish the component to resources/views/vendor/turnstile/components/turnstile-widget.blade.php.
You can now use it in your code:
Step 4: Configure Environment Variables
Add your Cloudflare Turnstile credentials to your .env file:
Get your keys from Cloudflare Dashboard.
- Go to Cloudflare Dashboard
- Navigate to Turnstile in the sidebar
- Click Add Site
- Enter your domain name
- Choose widget mode (recommended: Managed)
- Copy your Site Key and Secret Key
Usage
Step 1: Add Laravel Validation
You can add Laravel validation for the Cloudflare Turnstile response using one of the following methods:
Using the Validation Rule
Using the Facade
Middleware
Protect entire routes or route groups:
Step 2: Add Cloudflare Turnstile widget to the frontend
React / Inertia.js
Publish the React components using
Pass the sitekey to your component
Add the widget to you form using one of the following methods:
Using the React Component
Using the React Hook
TypeScript Types
The package includes full TypeScript support:
Blade Components
Publish the Blade components using
Add the component to your forms:
Customizing the Widget
Available options:
theme:auto,light, ordark(default:auto)size:normal,compact, orflexible(default:normal)field-name: Custom field name (default:cf-turnstile-response)callback: JavaScript callback function nameerror-callback: Error callback function nameexpired-callback: Expired callback function name
Configuration
The configuration file config/turnstile.php provides extensive customization:
Testing
The package automatically bypasses Turnstile verification when APP_ENV=testing or TURNSTILE_TESTING=true.
In Your Tests
Running Package Tests
Advanced Usage
Programmatic Verification
IP Whitelisting
Skip verification for trusted IPs (useful for local development):
Or in config/turnstile.php:
Custom Error Messages
Customize error messages in config/turnstile.php:
Controller Example (Complete)
Form Request Example
Troubleshooting
Widget Not Displaying
- Check that your site key is correct in
.env - Verify the script is loading: check browser console for errors
- Ensure you are not blocking Cloudflare domains
Verification Always Fails
- Check your secret key is correct
- Verify the token field name matches (default:
cf-turnstile-response) - Check server can reach Cloudflare's API
- Review error logs for detailed error codes
Testing Issues
Make sure TURNSTILE_TESTING=true or APP_ENV=testing is set in your test environment.
Error Codes
Cloudflare Turnstile may return the following error codes:
missing-input-secret- The secret parameter was not passedinvalid-input-secret- The secret parameter was invalidmissing-input-response- The response parameter was not passedinvalid-input-response- The response parameter is invalid or has expiredbad-request- The request was rejected because it was malformedtimeout-or-duplicate- The response parameter has already been validated before
Security
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
Credits
- Daniele De Santis
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
Support
For support, please open an issue on GitHub or contact [email protected].
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Developed by Daniele De Santis
All versions of laravel-cloudflare-turnstile-react-blade with dependencies
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/http Version ^10.0|^11.0|^12.0
guzzlehttp/guzzle Version ^7.0