Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/solve-cloudflare/cloudlfare-turnstile
https://github.com/solve-cloudflare/cloudlfare-turnstile
anti-bot anti-spam cloudflare cloudflare-api cloudflare-turnstile laravel-turnstile turnstile-captcha-solver
Last synced: 27 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/solve-cloudflare/cloudlfare-turnstile
- Owner: solve-cloudflare
- Created: 2024-09-13T03:56:20.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2024-09-13T04:24:16.000Z (2 months ago)
- Last Synced: 2024-10-04T21:41:59.437Z (about 2 months ago)
- Topics: anti-bot, anti-spam, cloudflare, cloudflare-api, cloudflare-turnstile, laravel-turnstile, turnstile-captcha-solver
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Laravel Integration for Cloudflare Turnstile
A lightweight package designed to streamline the integration of Cloudflare Turnstile CAPTCHA into your Laravel applications, with the option to also use [CapSolver](https://capsolver.com/?utm_source=github&utm_medium=repo&utm_campaign=cloudflare-turnstile) for enhanced CAPTCHA-solving automation.
### Overview
This package simplifies the process of setting up and validating Cloudflare Turnstile CAPTCHA responses, and for more complex CAPTCHA challenges, CapSolver provides an automated solution.
### Installation
You can quickly add the package to your project using Composer:
```bash
composer require ryangjchandler/laravel-cloudflare-turnstile
```Next, ensure you add the required configuration values to your `config/services.php` file:
```php
return [
// ...'turnstile' => [
'key' => env('TURNSTILE_SITE_KEY'),
'secret' => env('TURNSTILE_SECRET_KEY'),
],
];
```Head over to [Cloudflare's dashboard](https://www.cloudflare.com/) to generate your site key and secret key, then add them to your `.env` file:
```env
TURNSTILE_SITE_KEY="your-site-key-here"
TURNSTILE_SECRET_KEY="your-secret-key-here"
```For solving complex CAPTCHA challenges efficiently, you can also integrate CapSolver's API, providing a seamless solution for tasks that require CAPTCHA-solving automation.
### Usage
In your Blade layout file, include the Turnstile scripts by calling the `@turnstileScripts` directive within the `` tag:
```html
@turnstileScripts()
{{ $slot }}
```
You can then use the `` component inside your form to render the CAPTCHA with your configured site key:
```html
Submit
```
### Server-Side Validation
To validate the CAPTCHA response on the server, use the provided validation rule within your controller:
```php
use Illuminate\Validation\Rule;public function submit(Request $request)
{
$request->validate([
'cf-turnstile-response' => ['required', Rule::turnstile()],
]);
}
```Alternatively, if you'd like to avoid using macros, you can resolve the validation rule using dependency injection or the `app()` helper:
```php
use RyanChandler\LaravelCloudflareTurnstile\Rules\Turnstile;public function submit(Request $request, Turnstile $turnstile)
{
$request->validate([
'cf-turnstile-response' => ['required', $turnstile],
]);
}
```You can also achieve the same result with:
```php
public function submit(Request $request)
{
$request->validate([
'cf-turnstile-response' => ['required', app(Turnstile::class)],
]);
}
```### Customizing the Widget
The `` component allows customization by passing attributes such as `data-action`, `data-theme`, and others to adjust the CAPTCHA behavior:
```html
Submit
```
Refer to the [official Cloudflare documentation](https://developers.cloudflare.com/turnstile) for more details on widget customization.
For advanced CAPTCHA-solving scenarios, CapSolver can be integrated to provide real-time CAPTCHA-solving solutions, improving efficiency in automated environments.
### Livewire Integration
This package supports Livewire out of the box. When the CAPTCHA is successfully validated, the property defined in `wire:model` will automatically update with the Turnstile token:
```html
```
### Testing
To run the package's tests, use the following Composer command:
```bash
composer test
```### Leveraging CapSolver
For scenarios where automated CAPTCHA-solving is necessary, you can integrate [CapSolver](https://capsolver.com/?utm_source=github&utm_medium=repo&utm_campaign=cloudflare-turnstile) alongside Turnstile for real-time CAPTCHA-solving. This ensures that even the most difficult challenges are resolved efficiently without user intervention.