• Stars
    star
    183
  • Rank 202,660 (Top 5 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 1 year ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple package to help integrate Cloudflare Turnstile.

A simple package to help integrate Cloudflare Turnstile.

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This packages provides helper for setting up and validating Cloudflare Turnstile CAPTCHA responses.

Installation

You can install the package via Composer:

composer require ryangjchandler/laravel-cloudflare-turnstile

You should then add the following configuration values to your config/services.php file:

return [

    // ...,

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

];

Visit Cloudflare to create your site key and secret key and add them to your .env file.

TURNSTILE_SITE_KEY="1x00000000000000000000AA"
TURNSTILE_SECRET_KEY="2x0000000000000000000000000000000AA"

Usage

In your layout file, include the Turnstile scripts using the @turnstileScripts Blade directive. This should be added to the <head> of your document.

<html>
    <head>
        @turnstileScripts()
    </head>
    <body>
        {{ $slot }}
    </body>
</html>

Once that's done, you can use the <x-turnstile /> component inside of a <form> to output the appropriate markup with your site key configured.

<form action="/" method="POST">
    <x-turnstile />

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

On the server, use the provided validation rule to validate the CAPTCHA response.

use Illuminate\Validation\Rule;

public function submit(Request $request)
{
    $request->validate([
        'cf-turnstile-response' => ['required', Rule::turnstile()],
    ]);
}

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.

use RyanChandler\LaravelCloudflareTurnstile\Rules\Turnstile;

public function submit(Request $request, Turnstile $turnstile)
{
    $request->validate([
        'cf-turnstile-response' => ['required', $turnstile],
    ]);
}
use RyanChandler\LaravelCloudflareTurnstile\Rules\Turnstile;

public function submit(Request $request)
{
    $request->validate([
        'cf-turnstile-response' => ['required', app(Turnstile::class)],
    ]);
}

Customizing the widget

You can customize the widget by passing attributes to the <x-turnstile /> component.

To learn more about these parameters, refer to the offical documentation.

<form action="/" method="POST">
    <x-turnstile
        data-action="login"
        data-cdata="sessionid-123456789"
        data-callback="callback"
        data-expired-callback="expiredCallback"
        data-error-callback="errorCallback"
        data-theme="dark"
        data-tabindex="1"
    />

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

This package can also integrate seamlessly with Livewire. Upon successful validation, the property specified inside of wire:model will be updated with the Turnstile token.

<x-turnstile wire:model="yourModel" />

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

More Repositories

1

spruce

A lightweight state management layer for Alpine.js. 🌲
JavaScript
910
star
2

orbit

A flat-file database driver for Eloquent. 🗄
PHP
814
star
3

alpine-clipboard

Simply copy to the users clipboard in your Alpine.js components. 📋
JavaScript
317
star
4

alpine-tooltip

Add tooltips to your Alpine 3.x components with a custom directive.
JavaScript
289
star
5

laravel-comments

A dead-simple comments package for Laravel.
PHP
195
star
6

blade-cache-directive

Cache chunks of your Blade markup with ease. 🔪
PHP
186
star
7

alpine-hooks

A collection of hooks for use with Alpine.js.
JavaScript
176
star
8

laravel-feature-flags

An opinionated feature flags package for Laravel.
PHP
168
star
9

filament-navigation

Build structured navigation menus in Filament.
PHP
150
star
10

prettier-plugin-blade

Adds support for Blade templates to Prettier. (work in progress)
TypeScript
138
star
11

filament-profile

A simple profile management page for Filament. ✨
PHP
100
star
12

bearer

Minimalistic token-based authorization for Laravel API endpoints.
PHP
76
star
13

forge-previewer

Create preview deployments for pull requests with Laravel Forge.
PHP
69
star
14

blade-tabler-icons

A Blade icon pack for the Tabler icon set.
PHP
63
star
15

alpine-mask

A clean integration between Cleave.js and Alpine. ✨
JavaScript
60
star
16

cpx

Quickly execute Composer package binaries from anywhere. ⚡️
PHP
58
star
17

using

Enforced disposal of objects in PHP. 🐘
PHP
53
star
18

is-php-dead.lol

Is PHP dead?
PHP
48
star
19

blade-capture-directive

Create inline partials in your Blade templates with ease.
PHP
48
star
20

filament-progress-column

Add a progress bar column to your Filament tables.
PHP
47
star
21

filament-feature-flags

Control your Laravel feature flags through a clean Filament interface.
PHP
47
star
22

laravel-uuid

A small package for adding UUIDs to Eloquent models.
PHP
40
star
23

color

A simple Color object for PHP packages and applications. 🎨
PHP
38
star
24

cursed-html

Who said HTML wasn't a programming language?
JavaScript
37
star
25

filament-tools

Add a general-purpose tools page to your Filament project. 🛠
PHP
37
star
26

lexical

PHP
37
star
27

standalone-blade

Use Laravel's Blade templating engine outside of Laravel.
PHP
36
star
28

laravel-helpers

A collection of helper functions that I use across my projects.
PHP
34
star
29

phpast.com

A web tool to explore the ASTs generated by PHP-Parser.
PHP
32
star
30

laravel-json-settings

Store your Laravel application settings in an on-disk JSON file. ⚙️
PHP
31
star
31

lagoon

A dynamic, weakly-typed and minimal scripting language. 🏞
Rust
29
star
32

computed-properties

A small package to add computed properties to any PHP class. 🐘
PHP
27
star
33

phiki

A syntax highlighter for PHP inspired by Shiki.
PHP
27
star
34

fern

Persisted global stores for Alpine 3.x.
JavaScript
26
star
35

laravel-slug

Simple slugs for your Laravel models.
PHP
25
star
36

skeleton-laravel

PHP
25
star
37

x-else

An `x-else` directive for use in Alpine components. ✨
JavaScript
25
star
38

ryangjchandler.co.uk

My personal website, blog and project documentation.
PHP
22
star
39

laravel-expose

A clean integration between Laravel and Expose. ⚡️
PHP
21
star
40

filament-minimal-tabs

A clean and minimal design for the Tabs component in Filament.
CSS
20
star
41

alpine-parent

Adds a handy $parent magic property to your Alpine components.
JavaScript
18
star
42

alpine-toggle

Quickly toggle / negate a property in your Alpine.js components.
JavaScript
17
star
43

puny

Make unit testing in PHP simpler again. 👌
PHP
17
star
44

laravel-orphan-controller

Quickly identify controller methods with no route in your Laravel applications.
PHP
16
star
45

downmark

A speedy Markdown parser for PHP applications.
PHP
16
star
46

filament-log

A simplistic log viewer for your Filament apps.
PHP
15
star
47

stencil

A simple template engine for PHP written for a tutorial blog post.
PHP
15
star
48

git

A small PHP wrapper for Git. ✨
PHP
15
star
49

laravel-make-user

Quickly create `User` models with Artisan. ⚡️
PHP
14
star
50

fn-inspector

A utility package that helps inspect functions in PHP.
PHP
14
star
51

filament-user-resource

A simple resource for managing users in Filament.
PHP
13
star
52

tonic

An elegant language for script-kiddies and terminal squatters.
Rust
12
star
53

bytes

A class to help convert bytes into other units (kb, mb, etc).
PHP
12
star
54

laravel-make-view

A simple `make:view` command for Laravel applications.
PHP
10
star
55

laravel-rql

I don't like writing queries for CSV exports.
PHP
9
star
56

filament-color-palette

Let users pick a color from a fixed list of options.
PHP
8
star
57

fakeinator

Quickly generate CSV files full of fake data. 💽
HTML
7
star
58

container

A service container for PHP.
PHP
7
star
59

proxy

Proxy method and property interactions in PHP. ⚡️
PHP
7
star
60

laravel-auto-validate-models

A small package to auto-validate your Laravel models.
PHP
7
star
61

krypt

Share short-lived encrypted text messages with others.
PHP
6
star
62

uptime-checker

My personal uptime checker powered by Filament. ⚡️
PHP
6
star
63

repository

📦 A dead-simple repository class for use with Laravel.
PHP
5
star
64

rgjc.me

A disgustingly simple URL shortener powered by Laravel. 📶
PHP
5
star
65

laravel-restore-mix

A small CLI script that removes Vite in favour of Laravel Mix.
PHP
5
star
66

microphp

A small subset of PHP implemented in Rust. 🐘
Rust
5
star
67

rss-reader

An RSS reader application built with Laravel.
PHP
5
star
68

forge-previewer-action

A quick and easy way to get Forge Previewer running in GitHub Actions.
Dockerfile
5
star
69

paddle-demultiplexer

A simple serverless function to demultiplex Paddle webhooks.
TypeScript
4
star
70

phpbyexample.dev

A simple introduction to PHP with annotated code snippets.
CSS
4
star
71

template-rust-cli

A template for command-line Rust projects.
Python
4
star
72

peso

An elephant-ish esoteric programming language inspired by Brainf*ck.
PHP
4
star
73

typewrite.cc

A bring-your-own-email-first newsletter service. ✨
PHP
3
star
74

notepal

My personal note-taking application.
PHP
3
star
75

filament-plugin-search

Add a page to your Filament panel to search for plugins.
PHP
3
star
76

filament-simple-repeater

A single-field repeater for Filament. ⚡️
PHP
3
star
77

php-ffi-example

An example of using PHP + FFI with C, Rust and Go.
PHP
3
star
78

advent-of-code

Advent of Code Solutions in PHP
PHP
3
star
79

c-in-php

An incredibly cursed C interpreter written in PHP.
PHP
3
star
80

laravel-worldwide-demo

The demo used for my talk at October's Laravel Worldwide Meetup.
PHP
2
star
81

rook-lang

A small scripting language running on V8.
Rust
2
star
82

filament-data-studio

Low configuration exports and data analysis for Filament.
PHP
2
star
83

filament-passwordless-login

PHP
2
star
84

60-second-laravel

The demo application used in the 60 Second Laravel series.
PHP
2
star
85

pl

A toy language implemented in Rust. 🦀
Rust
2
star
86

curl-to-laravel-http

PHP
2
star
87

filament-plausible-page

Embed your site's Plausible dashboard inside of Filament.
PHP
2
star
88

laravel-slack-webhook

A fluent package for building Slack webhook payloads.
PHP
2
star
89

mathexpr

A tiny math expression evaluator written in PHP.
PHP
2
star
90

alpinejs-mobile

Swift
2
star
91

polling-app

A simple polling application built with the TALL stack. 🗼
PHP
2
star
92

laravel-restore-command

An Artisan command to quickly restore soft-deleted models. ⚡
PHP
2
star
93

php-parser-specs

A set of specification tests for PHP parsers, used to improve compliance and acceptance.
PHP
2
star
94

laravel-synchro

Easily sync and anonymise your data between environments.
PHP
2
star
95

blade-validator

Run rudimentary linting checks on your Blade templates.
PHP
1
star
96

expr

A powerful expression engine designed for business rules and sandboxed execution. 🔡
PHP
1
star
97

blade-in-directive

A tidy conditional Blade directive for checking if something is in an array.
PHP
1
star
98

chains

Gold, silver, diamonds, tiny ol' JavaScript framework.
JavaScript
1
star
99

symbol-interner

A simple string interner / symbol table for Rust projects.
Rust
1
star
100

filament-sanctum

Manage your Sanctum tokens inside of Filament. ✨
PHP
1
star