News

Integrate Cloudflare Turnstile into Laravel and Livewire

Published
Integrate Cloudflare Turnstile into Laravel and Livewire image

Want to integrate Cloudflare Turnstile CAPTCHA into your Laravel or Livewire app? This package from Ryan Chandler makes integration super simple.

Cloudflare Turnstile for Laravel Usage

Include the Turnstile scripts using the @turnstileScripts Blade directive in the <head> of your layout file.

<html>
<head>
@turnstileScripts()
</head>
<body>
{{ $slot }}
</body>
</html>

After that, use the <x-turnstile /> component inside a <form>:

<form action="/" method="POST">
<x-turnstile />
 
<button>
Submit
</button>
</form>

Use the provided validation rule on the server to validate the CAPTCHA response.

use Illuminate\Validation\Rule;
 
public function submit(Request $request)
{
$request->validate([
'cf-turnstile-response' => ['required', Rule::turnstile()],
]);
}

Cloudflare Turnstile with Livewire

This package can also integrate seamlessly with Livewire. Upon successful validation, the property specified inside of wire:model will be updated with the Turnstile token.

<x-turnstile wire:model="yourModel" />

Check out the package on GitHub for more details on customizing and integrating it into your app.

Eric L. Barnes photo

Eric is the creator of Laravel News and has been covering Laravel since 2012.

Filed in

Sponsored

laravelcloud logo
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud

The latest

View all →
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article
Laravel AI SDK Adds Human-in-the-Loop Tool Approval image

Laravel AI SDK Adds Human-in-the-Loop Tool Approval

Read article
Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals image

Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals

Read article
Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs image

Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs

Read article
Blade Formatting in Laravel Pint image

Blade Formatting in Laravel Pint

Read article
Inertia DevTools Is Now on the Chrome Web Store image

Inertia DevTools Is Now on the Chrome Web Store

Read article