https://github.com/teampanfu/laravel-turnstile
A Laravel package for Cloudflare's Turnstile CAPTCHA service.
https://github.com/teampanfu/laravel-turnstile
captcha cloudflare laravel standalone turnstile
Last synced: 3 months ago
JSON representation
A Laravel package for Cloudflare's Turnstile CAPTCHA service.
- Host: GitHub
- URL: https://github.com/teampanfu/laravel-turnstile
- Owner: teampanfu
- License: mit
- Created: 2023-07-17T00:43:47.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-02-15T06:26:31.000Z (5 months ago)
- Last Synced: 2025-03-17T06:16:43.630Z (4 months ago)
- Topics: captcha, cloudflare, laravel, standalone, turnstile
- Language: PHP
- Homepage: https://developers.cloudflare.com/turnstile
- Size: 26.4 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Turnstile for Laravel
[](https://github.com/teampanfu/laravel-turnstile/releases)
[](https://packagist.org/packages/teampanfu/laravel-turnstile)
[](LICENSE)A Laravel package that integrates [Cloudflare's Turnstile](https://developers.cloudflare.com/turnstile) CAPTCHA service.
## Requirements
For Laravel integration:
- PHP 8.2 or higher
- [Laravel](https://laravel.com) 9 or higherFor standalone usage:
- PHP 8.2 or higher
- [Guzzle HTTP](https://docs.guzzlephp.org) 7.8 or higher## Installation
```sh
composer require teampanfu/laravel-turnstile
```## Laravel Integration
1. Add to your `.env`:
```
TURNSTILE_SITEKEY=1x00000000000000000000AA
TURNSTILE_SECRET=1x0000000000000000000000000000000AA
```### Add the Widget
```blade
@csrf
Submit```
See [available configurations](https://developers.cloudflare.com/turnstile/get-started/client-side-rendering/#configurations) for theme, language, etc.
### Validate the Response
```php
$request->validate([
'cf-turnstile-response' => ['turnstile'],
]);
```### Custom Error Message
In `lang/[lang]/validation.php`:
```php
'custom' => [
'cf-turnstile-response' => [
'turnstile' => 'Please verify that you are human.',
],
],
```## Standalone Usage
The package can also be used without Laravel:
```php
validate($_POST['cf-turnstile-response'])) {
// Verification successful
}
} catch (\RuntimeException $e) {
// Handle validation error (e.g., invalid-input-response)
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
// Handle network/request error
}
```## Testing
```sh
./vendor/bin/phpunit
```## License
[MIT License](LICENSE)