PHP code example of hansdeboeck / laravel-turnstile
1. Go to this page and download the library: Download hansdeboeck/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/ */
hansdeboeck / laravel-turnstile example snippets
use HansDeBoeck\Turnstile\Facades\Turnstile;
// Als validatieregel, de kortste weg:
$request->validate([
'turnstile_token' => 'oken'))) {
return back()->withErrors(['turnstile_token' => 'Verificatie mislukt.']);
}
// Met het volledige resultaat:
$result = Turnstile::verify($token);
$result->passed; // bool
$result->skipped; // geslaagd omdat de omgeving de controle overslaat
$result->failure; // missing-token | not-configured | http-error | rejected
$result->forLogging();
js
const gate = window.turnstileGate.create({
stage: document.querySelector('[data-turnstile-stage]'),
container: '#mijn-container',
});
gate.token()
.then((token) => { /* meesturen met je fetch */ })
.catch((error) => {
if (gate.isCancelled(error)) return; // bezoeker brak zelf af
if (gate.isExpired(error)) return; // token verliep, opnieuw proberen
// echte storing
});
gate.reset();
gate.destroy(); // nodig zodra een dialoog uit de DOM verdwijnt