PHPackages                             njoguamos/laravel-turnstile - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. njoguamos/laravel-turnstile

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

njoguamos/laravel-turnstile
===========================

A laravel wrapper for https://developers.cloudflare.com/turnstile/

v4.0.0(2mo ago)2315.9k↓33.5%21MITPHPPHP ^8.3 | ^8.4 | ^8.5CI passing

Since Jan 31Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/njoguamos/laravel-turnstile)[ Packagist](https://packagist.org/packages/njoguamos/laravel-turnstile)[ Docs](https://github.com/njoguamos/laravel-turnstile)[ RSS](/packages/njoguamos-laravel-turnstile/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (24)Versions (15)Used By (1)

[![Cover image](/cover.png)](/cover.png)

Cloudflare Turnstile for Laravel 10+
====================================

[](#cloudflare-turnstile-for-laravel-10)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2d471f34389f376219f69c6f19b147d50c6aecb2edda0c793e69cf10052c59ba/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6a6f6775616d6f732f6c61726176656c2d7475726e7374696c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/njoguamos/laravel-turnstile)[![GitHub Tests Action Status](https://camo.githubusercontent.com/b3bc6837c1b6eae9fd522d860d92104a0cee3941ba04571c7344c0407f073b1c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6e6a6f6775616d6f732f6c61726176656c2d7475726e7374696c652f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/njoguamos/laravel-turnstile/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/a52af9a68a55cd33e48fbedbb8e6c176a618b4f4f9875f8ef92b3aaf138e1c15/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6e6a6f6775616d6f732f6c61726176656c2d7475726e7374696c652f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/njoguamos/laravel-turnstile/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/1fa2767e6cf1116b48c6fc1b695caf7aba04db121aa305bd88c8ea7ce2910665/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e6a6f6775616d6f732f6c61726176656c2d7475726e7374696c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/njoguamos/laravel-turnstile)

[Turnstile](https://developers.cloudflare.com/turnstile/) is a new user-friendly, privacy preserving alternative to CAPTCHA. This package provides a flexible way of integrating turnstile into your Laravel application. This package can be turned on and off for your convenience.

> **Info**This package focuses on server side validation. You are free to implement your preferable client side technology such vue, reach, blade e.t.c

Version compatibility
---------------------

[](#version-compatibility)

VersionPHP versionsLaravel versions1.x8.0, 8.1 and 8.29.x and 10.x2.x8.1, 8.2 and 8.310.x and 11.x3.x8.2, 8.3 and 8.411.x and 12.x4.x8.3, 8.4 and 8.512.x and 13.xInstallation
------------

[](#installation)

You can install the package via composer:

```
composer require njoguamos/laravel-turnstile
```

You can initialise the package with:

```
php artisan turnstile:install
```

The install command will publish the [config file](/config/turnstile.php).

Ensure that you have update your application `.env` with credentials from [cloudflare](https://developers.cloudflare.com/turnstile/get-started/) i.e.

```
TURNSTILE_SITE_KEY=
TURNSTILE_SECRET_KEY=
TURNSTILE_ENABLED=true
#TURNSTILE_ENABLED=false -> when you want to disable e.g when testing
```

Usage
-----

[](#usage)

There are three way to use this package.

### 1. As a middleware

[](#1-as-a-middleware)

To use turnstile is specific routes of your application, you can register a new middleware in your laravel `app/Http/Kernel.php`.

```
class Kernel extends HttpKernel {
    // other class code

    protected $routeMiddleware = [
    // Other middlewares
        'turnstile' => \NjoguAmos\Turnstile\Http\Middleware\TurnstileMiddleware::class
    ];
}
```

Once the middleware has been defined in the HTTP kernel, you may use the middleware method to assign middleware to a route:

```
Route::get('/register', function () {
    //
})->middleware('turnstile');
```

Ensure your client side technology submit a turnstile token using a name defined in turnstile config file. Your can learn how to implement client side render from [cloudflare website](https://developers.cloudflare.com/turnstile/get-started/client-side-rendering/#implicitly-render-the-turnstile-widget). Example:

Upon submitting the form, the turnstile token will be validated against turnstile api. If it fails, the request will be redirected back with `status` message. You can handle this message however you want in client side.

### 2. As a validation rule (v2.x.x)

[](#2-as-a-validation-rule-v2xx)

You can user the inbuilt validation to validate form input

```
use NjoguAmos\Turnstile\Rules\TurnstileRule;

class RegisterRequest extends FormRequest
{
    /** @return array */
    public function rules(): array
    {
        return [
            # Other fields
            'token'   => ['required', new TurnstileRule() ],
        ];
    }

    # Other code
}
```

### 3. Manual

[](#3-manual)

You can validate turnstile token by calling validate method of `Turnstile` facade. The result will be `true` when token passed and `false` when token fails.

```
use NjoguAmos\Turnstile\Turnstile;

$isValid = (new Turnstile())->validate($token);

// Code is valid or invalid
```

If you would like to have more control on the response, you can use `getResponse` method of `Turnstile` facade. The result will be an instance of `TurnstileResponse` class.

```
use NjoguAmos\Turnstile\Turnstile;

$response = (new Turnstile())->getResponse($token);

// Result is an instance of \NjoguAmos\Turnstile\TurnstileResponse
```

Disabling
---------

[](#disabling)

To increase the speed of your unit tests, you may wish to disable the turnstile. You can do so by setting `TURNSTILE_ENABLED` to false. i.e

```
#.env
TURNSTILE_ENABLED=false
```

When disabled,

- turnstile middleware will always pass
- turnstile validation rule will always pass

😀 Remember to turn turnstile on when you deploy.

Testing
-------

[](#testing)

> **Info**This package does not mock request. It uses the secret keys [provided by Cloudflare](https://developers.cloudflare.com/turnstile/reference/testing/). Therefore, test scenarios hits the real turnstile api.

```
composer test
```

Changelog
---------

[](#changelog)

Please see [releases](https://github.com/njoguamos/laravel-turnstile/releases) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Njogu Amos](https://github.com/njoguamos)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance88

Actively maintained with recent releases

Popularity36

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 87.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~103 days

Recently: every ~119 days

Total

12

Last Release

62d ago

Major Versions

v1.1.0 → v2.1.02024-02-11

v2.2.2 → v3.0.02024-11-23

v3.2.2 → v4.0.02026-03-17

PHP version history (4 changes)v1.0.0PHP ^8.0 | ^8.1 | ^8.2

v2.1.0PHP ^8.1 | ^8.2 | ^8.3

v3.0.0PHP ^8.2 | ^8.3 | ^8.4

v4.0.0PHP ^8.3 | ^8.4 | ^8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/1262b428518ef976f4268074e0b9e9280ec9af765aee553112bea64401beed8f?d=identicon)[njoguamos](/maintainers/njoguamos)

---

Top Contributors

[![njoguamos](https://avatars.githubusercontent.com/u/29255728?v=4)](https://github.com/njoguamos "njoguamos (86 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (10 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")[![Kovah](https://avatars.githubusercontent.com/u/1816101?v=4)](https://github.com/Kovah "Kovah (1 commits)")

---

Tags

cloudflarelaravelphpturnstilelaravelturnstilenjoguamos

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/njoguamos-laravel-turnstile/health.svg)

```
[![Health](https://phpackages.com/badges/njoguamos-laravel-turnstile/health.svg)](https://phpackages.com/packages/njoguamos-laravel-turnstile)
```

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k89.8M1.0k](/packages/spatie-laravel-permission)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[jeffgreco13/filament-breezy

A custom package for Filament with login flow, profile and teams support.

1.0k1.7M41](/packages/jeffgreco13-filament-breezy)[spatie/laravel-login-link

Quickly login to your local environment

4381.2M1](/packages/spatie-laravel-login-link)[ryangjchandler/laravel-cloudflare-turnstile

A simple package to help integrate Cloudflare Turnstile.

438896.6k2](/packages/ryangjchandler-laravel-cloudflare-turnstile)[spatie/laravel-passkeys

Use passkeys in your Laravel app

444494.4k16](/packages/spatie-laravel-passkeys)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
