Download the PHP package siberfx/cloudflare-turnstile without Composer
On this page you can find all versions of the php package siberfx/cloudflare-turnstile. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download siberfx/cloudflare-turnstile
More information about siberfx/cloudflare-turnstile
Files in siberfx/cloudflare-turnstile
Package cloudflare-turnstile
Short Description Cloudflare Turnstile CAPTCHA integration for Laravel: Blade widget, validation rule, middleware and testing fake.
License MIT
Informations about the package cloudflare-turnstile
Cloudflare Turnstile for Laravel
Protect your Laravel forms with Cloudflare Turnstile, the privacy-first CAPTCHA alternative.
<x-turnstile />Blade component. It loads the script once per page.- Validation rule (
new Turnstile,Rule::turnstile()), with expected-action support turnstileroute middleware- Optional hostname allow-list and remote IP forwarding
- Rich
VerificationResultobject (hostname, action, cdata, timestamp, ephemeral ID) - Octane-safe. Tokens are redeemed once per request, even if the rule and middleware both run
Turnstile::fake()for your own tests- Translations: English, Turkish, Dutch, German and Russian
Requirements
| Package | Version |
|---|---|
| PHP | 8.4, 8.5 |
| Laravel | 12.x, 13.x |
Installation
Add your keys (Cloudflare dashboard → Turnstile → Add widget) to .env:
Optionally publish everything (config, views and translations) with a single command:
Or publish only what you need:
Rendering the widget
Place the component inside your form:
The Cloudflare script is included automatically, only once per page. To load it yourself (e.g. in your <head>), pass :script="false" and use the directive:
Options
Every option maps to a data-* attribute. Defaults come from config('turnstile.widget'):
Validating
Validation rule
The rule is implicit, so a missing token also fails. To check that the token came from a widget with a specific action, use:
Middleware
Safe methods (GET, HEAD, OPTIONS) are skipped. When verification fails, the middleware throws a ValidationException on the cf-turnstile-response field. You get the usual redirect with errors, or a 422 JSON response.
Manual verification
Error handling
Error codes are exposed as the Siberfx\Turnstile\Enums\ErrorCode enum. Next to Cloudflare's own codes, the package adds:
| Code | Meaning |
|---|---|
connection-failed |
Cloudflare could not be reached (after the retries you configured) |
hostname-mismatch |
Hostname isn't in turnstile.hostnames |
action-mismatch |
Widget action differs from the expected action |
Visitors see one of four friendly messages: failed, missing, expired, unavailable. Publish the translations to change them.
ErrorCode::isConfigurationError() helps you tell a wrong secret key apart from a bad visitor.
Configuration
| Key | Env | Default |
|---|---|---|
enabled |
TURNSTILE_ENABLED |
true |
site_key |
TURNSTILE_SITE_KEY |
null |
secret_key |
TURNSTILE_SECRET_KEY |
null |
timeout |
TURNSTILE_TIMEOUT |
5 seconds |
retries |
TURNSTILE_RETRIES |
1 (connection errors only) |
send_remote_ip |
TURNSTILE_SEND_REMOTE_IP |
true |
hostnames |
TURNSTILE_HOSTNAMES |
[] (comma separated in env) |
field |
cf-turnstile-response |
|
widget.* |
TURNSTILE_THEME, TURNSTILE_SIZE |
auto, normal |
When enabled is false, every verification passes without a network call. This is useful in local development.
Cloudflare test keys
| Site key | Behaviour |
|---|---|
1x00000000000000000000AA |
Always passes |
2x00000000000000000000AB |
Always blocks |
3x00000000000000000000FF |
Forces a challenge |
| Secret key | Behaviour |
|---|---|
1x0000000000000000000000000000000AA |
Always passes |
2x0000000000000000000000000000000AA |
Always fails |
3x0000000000000000000000000000000AA |
Yields "token already spent" |
Testing your application
Other fake helpers: respondWith(VerificationResult|Closure), assertNotVerified(), assertVerifiedTimes(int), recorded().
Development
License
MIT. See LICENSE.
All versions of cloudflare-turnstile with dependencies
illuminate/console Version ^12.0|^13.0
illuminate/contracts Version ^12.0|^13.0
illuminate/http Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0
illuminate/validation Version ^12.0|^13.0
illuminate/view Version ^12.0|^13.0