1. Go to this page and download the library: Download snipify-dev/laravel-captcha 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/ */
snipify-dev / laravel-captcha example snippets
namespace App\Livewire;
use Livewire\Component;
use SnipifyDev\LaravelCaptcha\Rules\RecaptchaValidationRule;
class ContactForm extends Component
{
public $name = '';
public $email = '';
public $message = '';
public $captchaToken = '';
public function submit()
{
$this->validate([
'name' => ' render()
{
return view('livewire.contact-form');
}
}
use Illuminate\Http\Request;
use SnipifyDev\LaravelCaptcha\Rules\RecaptchaValidationRule;
class ContactController extends Controller
{
public function store(Request $request)
{
$validated = $request->validate([
'name' => 'th('success', 'Message sent!');
}
}
// Basic usage with any action name
new RecaptchaValidationRule('login')
new RecaptchaValidationRule('contact')
new RecaptchaValidationRule('signup')
new RecaptchaValidationRule('any_action_name')
// Force specific version if needed
new RecaptchaValidationRule('login', null, 'v2') // Force v2
new RecaptchaValidationRule('login', null, 'v3') // Force v3
public function test_contact_form_submission()
{
$response = $this->post('/contact', [
'name' => 'John Doe',
'email' => '[email protected]',
'message' => 'Test message',
'captchaToken' => 'fake-token', // Ignored in testing
]);
$response->assertRedirect()->assertSessionHas('success');
}