Looking to hire Laravel developers? Try LaraJobs

turnstile-for-laravel maintained by vincenzoraco

Description
Laravel package to facilitate the server side validation of Cloudflare's Turnstile captcha service.
Author
Last update
2026/04/16 06:09 (dev-main)
License
Links
Downloads
74

Comments
comments powered by Disqus

A package to facilitate the server side validation of Cloudflare's Turnstile captcha service.

[!NOTE] This package requires PHP 8.3+ and Laravel 11+

Installation

You can install the package via composer:

composer require vincenzoraco/turnstile-for-laravel

Usage

Once installed, set the following ENV:

TURNSTILE_SECRET_KEY=
TURNSTILE_SITE_KEY=

Then publish the config file:

php artisan vendor:publish --tag=turnstile-config

[!NOTE] TURNSTILE_SITE_KEY is only for your convenience to have it in the config

You can then use the validation rule:

use VincenzoRaco\TurnstileLaravel\Rules\TurnstileCheck;

$request->validate([
    'cf-turnstile-response' => ['required', new TurnstileCheck],
]);

Or use the facade directly:

use VincenzoRaco\Turnstile\DataObjects\TurnstileValidateDTO;
use VincenzoRaco\TurnstileLaravel\Facades\Turnstile;

$result = Turnstile::validate(new TurnstileValidateDTO(
    $token,
));

if ($result->isFailure()) {
    throw new CaptchaException; // custom exception
}