PHPackages                             kalprajsolutions/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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. kalprajsolutions/laravel-turnstile

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

kalprajsolutions/laravel-turnstile
==================================

A Laravel Blade component for Cloudflare Turnstile CAPTCHA integration

1.0.0(3mo ago)113MITBladePHP ^8.1

Since Mar 11Pushed 3mo agoCompare

[ Source](https://github.com/kalprajsolutions/laravel-turnstile)[ Packagist](https://packagist.org/packages/kalprajsolutions/laravel-turnstile)[ RSS](/packages/kalprajsolutions-laravel-turnstile/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

 [   ![Logo for Laravel Wordpress CDA](https://github.com/Pushkraj19/Pushkraj19/raw/d72ff5e2eb7299546cd8348c25fd835a39becce0/laravel-turnstile.png)  ](https://kalprajsolutions.com/?utm_source=github&utm_medium=banner&utm_campaign=laravel-turnstile)

Laravel Turnstile
=================

[](#laravel-turnstile)

[![License](https://camo.githubusercontent.com/dd939d1a26e4b5079829add26191e96ecff5520425259ce6880e56ae097c2413/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6b616c7072616a736f6c7574696f6e732f6c61726176656c2d7475726e7374696c652e737667)](https://packagist.org/packages/kalprajsolutions/laravel-turnstile)[![Total Downloads](https://camo.githubusercontent.com/93acb438a3d4d468694d1c8eba6e26cdf2fa32c5e4c681e78d80e4d9d135196c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b616c7072616a736f6c7574696f6e732f6c61726176656c2d7475726e7374696c652e737667)](https://packagist.org/packages/kalprajsolutions/laravel-turnstile)[![Latest Version](https://camo.githubusercontent.com/e5f7a192eb65b0d34c71ecc36c8eca4091c1ed95f6fc7c4e6a0463753deacf57/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b616c7072616a736f6c7574696f6e732f6c61726176656c2d7475726e7374696c652e737667)](https://packagist.org/packages/kalprajsolutions/laravel-turnstile)[![Laravel](https://camo.githubusercontent.com/6df2d4c6731ff9ed4ff318ba740621b43e7abfb38c5088bdb418cb2f0cbc52f0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d382532422d6f72616e67652e737667)](https://laravel.com)

A Laravel package for easy integration of Cloudflare Turnstile CAPTCHA into your forms. Provides a simple Blade component with both standard and lazy loading modes for optimal user experience.

Description
-----------

[](#description)

Laravel Turnstile provides a seamless way to integrate Cloudflare's Turnstile CAPTCHA into your Laravel applications. Unlike traditional CAPTCHAs, Turnstile is user-friendly and doesn't require users to solve puzzles, making it invisible to most legitimate users while still protecting your forms from bots.

### Features

[](#features)

- **Easy Integration** - Simple Blade component to add Turnstile to any form
- **Standard Mode** - Widget loads immediately, buttons disabled until verification
- **Lazy Mode** - Widget appears only when user attempts to submit
- **Multiple Widgets** - Support for multiple Turnstile widgets on the same page
- **Livewire Support** - Built-in integration with Livewire components
- **Server-side Validation** - Multiple ways to validate the Turnstile response

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require kalprajsolutions/laravel-turnstile
```

The package will automatically register its service provider. If you're using Laravel 10 or below, you may need to manually add the service provider to your `config/app.php`.

### Publish Component (Optional)

[](#publish-component-optional)

If you need to customize the configuration, publish the view file:

```
php artisan vendor:publish --provider="KalprajSolutions\LaravelTurnstile\TurnstileServiceProvider"
```

Configuration
-------------

[](#configuration)

### Environment Variables

[](#environment-variables)

Add your Cloudflare Turnstile credentials to your `.env` file:

```
CLOUDFLARE_SITE_KEY=your_site_key_here
CLOUDFLARE_SECRET_KEY=your_secret_key_here
```

### Services Configuration

[](#services-configuration)

The package uses Laravel's `config/services.php` structure. Add the following to your `config/services.php` file:

```
'cloudflare' => [
    'site_key' => env('CLOUDFLARE_SITE_KEY'),
    'secret_key' => env('CLOUDFLARE_SECRET_KEY'),
    'endpoint' => 'https://challenges.cloudflare.com/turnstile/v0/siteverify',
],
```

### Getting Your Cloudflare Credentials

[](#getting-your-cloudflare-credentials)

1. Go to [Cloudflare Dashboard](https://dash.cloudflare.com/)
2. Navigate to **Turnstile** under the **Security** section
3. Create a new site and get your Site Key and Secret Key
4. Make sure to add your domain to the allowed domains list

Usage
-----

[](#usage)

### Basic Usage (Standard Mode)

[](#basic-usage-standard-mode)

In standard mode, the Turnstile widget loads immediately when the page loads. Form buttons are disabled until the user completes the verification.

```

    @csrf

        Name:

        Email:

    Send Message

```

The component automatically includes a hidden input named `cf-turnstile-response` containing the verification token.

### Lazy Mode

[](#lazy-mode)

In lazy mode, the widget remains hidden until the user attempts to submit the form. This provides a cleaner user experience by only showing the CAPTCHA when needed.

```

    @csrf

    Subscribe

```

### Customizing Appearance

[](#customizing-appearance)

```

```

### Multiple Widgets on Same Page

[](#multiple-widgets-on-same-page)

The component automatically handles multiple instances with unique IDs:

```

    @csrf

    Login

    @csrf

    Register

```

### Custom JavaScript Callbacks

[](#custom-javascript-callbacks)

```

function onTurnstileSuccess(token) {
    console.log('Verification successful:', token);
    // Custom logic here - e.g., enable additional fields
}

```

### Livewire Integration

[](#livewire-integration)

For Livewire components, use the callback to bind the token to a Livewire property:

```

        Submit

    function onTurnstileSuccess(token) {
        console.log('Verification successful:', token);
        // Bind token to Livewire
        @this.set('turnstileToken', token);
    }

```

```
