PHP code example of ryangjchandler / laravel-cloudflare-turnstile

1. Go to this page and download the library: Download ryangjchandler/laravel-cloudflare-turnstile library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ryangjchandler / laravel-cloudflare-turnstile example snippets


return [

    // ...,

    'turnstile' => [
        'key' => env('TURNSTILE_SITE_KEY'),
        'secret' => env('TURNSTILE_SECRET_KEY'),
    ],

];

use Illuminate\Validation\Rule;
use RyanChandler\LaravelCloudflareTurnstile\Rules\Turnstile;

public function submit(Request $request)
{
    $request->validate([
        'cf-turnstile-response' => ['

use RyanChandler\LaravelCloudflareTurnstile\Facades\Turnstile;

Turnstile::fake(): // Force a successful response.
Turnstile::fake()->fail(); // Force a failed response.
Turnstile::fake()->expired(); // Force an expired token response.

post('/my-form', [
    'cf-turnstile-response' => Turnstile::dummy(),
])
blade
<form action="/" method="POST">
    <x-turnstile />

    <button>
        Submit
    </button>
</form>