Skip to content

Commit 2138c91

Browse files
chore: docs
1 parent e0f7dca commit 2138c91

File tree

1 file changed

+71
-26
lines changed

1 file changed

+71
-26
lines changed

README.md

Lines changed: 71 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,100 @@
55
[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/ryangjchandler/laravel-cloudflare-turnstile/Fix%20PHP%20code%20style%20issues?label=code%20style)](https://github.com/ryangjchandler/laravel-cloudflare-turnstile/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
66
[![Total Downloads](https://img.shields.io/packagist/dt/ryangjchandler/laravel-cloudflare-turnstile.svg?style=flat-square)](https://packagist.org/packages/ryangjchandler/laravel-cloudflare-turnstile)
77

8-
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
8+
This packages provides helper for setting up and validating Cloudflare Turnstile CAPTCHA responses.
99

10-
## Support us
10+
## Installation
1111

12-
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/laravel-cloudflare-turnstile.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/laravel-cloudflare-turnstile)
12+
You can install the package via Composer:
1313

14-
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
14+
```bash
15+
composer require ryangjchandler/laravel-cloudflare-turnstile
16+
```
1517

16-
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
18+
You should then add the following configuration values to your `config/services.php` file:
1719

18-
## Installation
20+
```php
21+
return [
1922

20-
You can install the package via composer:
23+
// ...,
2124

22-
```bash
23-
composer require ryangjchandler/laravel-cloudflare-turnstile
25+
'turnstile' => [
26+
'key' => env('TURNSTILE_SITE_KEY'),
27+
'secret' => env('TURNSTILE_SECRET_KEY'),
28+
],
29+
30+
];
2431
```
2532

26-
You can publish and run the migrations with:
33+
Visit Cloudflare to create your site key and secret key and add them to your `.env` file.
2734

28-
```bash
29-
php artisan vendor:publish --tag="laravel-cloudflare-turnstile-migrations"
30-
php artisan migrate
35+
```
36+
TURNSTILE_SITE_KEY="1x00000000000000000000AA"
37+
TURNSTILE_SECRET_KEY="2x0000000000000000000000000000000AA"
3138
```
3239

33-
You can publish the config file with:
40+
## Usage
3441

35-
```bash
36-
php artisan vendor:publish --tag="laravel-cloudflare-turnstile-config"
42+
In your layout file, include the Turnstile scripts using the `@turnstileScripts` Blade directive. This should be added to the `<head>` of your document.
43+
44+
```blade
45+
<html>
46+
<head>
47+
@turnstileScripts()
48+
</head>
49+
<body>
50+
{{ $slot }}
51+
</body>
52+
</html>
3753
```
3854

39-
This is the contents of the published config file:
55+
Once that's done, you can use the `@turnstile` directive in `<form>` to output the appropriate markup with your site key configured.
4056

41-
```php
42-
return [
43-
];
57+
```blade
58+
<form action="/" method="POST">
59+
@turnstile()
60+
61+
<button>
62+
Submit
63+
</button>
64+
</form>
4465
```
4566

46-
Optionally, you can publish the views using
67+
On the server, use the provided validation rule to validate the CAPTCHA response.
4768

48-
```bash
49-
php artisan vendor:publish --tag="laravel-cloudflare-turnstile-views"
69+
```php
70+
use Illuminate\Validation\Rule;
71+
72+
public function submit(Request $request)
73+
{
74+
$request->validate([
75+
'cf-turnstile-response' => ['required', Rule::turnstile()],
76+
]);
77+
}
5078
```
5179

52-
## Usage
80+
If you prefer to not use a macro, you can resolve an instance of the rule from the container via dependency injection or the `app()` helper.
81+
82+
```php
83+
use RyanChandler\LaravelCloudflareTurnstile\Rules\Turnstile;
84+
85+
public function submit(Request $request, Turnstile $turnstile)
86+
{
87+
$request->validate([
88+
'cf-turnstile-response' => ['required', $turnstile],
89+
]);
90+
}
91+
```
5392

5493
```php
55-
$laravelCloudflareTurnstile = new RyanChandler\LaravelCloudflareTurnstile();
56-
echo $laravelCloudflareTurnstile->echoPhrase('Hello, RyanChandler!');
94+
use RyanChandler\LaravelCloudflareTurnstile\Rules\Turnstile;
95+
96+
public function submit(Request $request)
97+
{
98+
$request->validate([
99+
'cf-turnstile-response' => ['required', app(Turnstile::class)],
100+
]);
101+
}
57102
```
58103

59104
## Testing

0 commit comments

Comments
 (0)