1. Go to this page and download the library: Download coderflex/laravel-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/ */
coderflex / laravel-turnstile example snippets
return [
/*
|--------------------------------------------------------------------------
| Turnstile Keys
|--------------------------------------------------------------------------
|
| This value is the site, and the secret key of your application, after creating an application
| with Cloudflare turnstile, copy the site key, and use it here, or in the .env
| file.
| Note that the secret key should not be publicly accessible.
|
| @see: https://developers.cloudflare.com/turnstile/get-started/#get-a-sitekey-and-secret-key
|
*/
'turnstile_site_key' => env('TURNSTILE_SITE_KEY', null),
'turnstile_secret_key' => env('TURNSTILE_SECRET_KEY', null),
/*
|--------------------------------------------------------------------------
| Error Messages
|--------------------------------------------------------------------------
|
| Here you can find the error messages for the application. You can modify
| or translate the error message as you like.
|
| Note that you can translate the error message directly, without wrapping
| them in translate helper.
|
*/
'error_messages' => [
'turnstile_check_message' => 'The CAPTCHA thinks you are a robot! Please refresh and try again.',
],
];
use Coderflex\LaravelTurnstile\Facades\LaravelTurnstile;
public function store(Request $request)
{
// maybe you want to validate your form first
$response = LaravelTurnstile::validate();
if (! $response['success']) { // will return boolean
// do your logic
}
}
public function store(Request $request)
{
...
$response = LaravelTurnstile::validate(
$request->get('cf-turnstile-response'); // this will be created from the cloudflare widget.
);
...
}
use Coderflex\LaravelTurnstile\Rules\TurnstileCheck;
public function store(Request $request)
{
$request->validate([
'cf-turnstile-response' => [new TurnstileCheck()]
]);
}
return [
...
'error_messages' => [
'turnstile_check_message' => 'The CAPTCHA thinks you are a robot! Please refresh and try again.',
],
];
use Coderflex\LaravelTurnstile\Rules\TurnstileCheck;
use Coderflex\LaravelTurnstile\Facades\LaravelTurnstile;
...
public function store(Request $request)
{
$request->validate([
'name' => ['
// do your things.
}