PHP code example of elysdan / emcaptcha

1. Go to this page and download the library: Download elysdan/emcaptcha 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/ */

    

elysdan / emcaptcha example snippets


use Elysdan\EMCaptcha\Rules\ValidCaptcha;

public function store(Request $request)
{
    $request->validate([
        'captcha' => ['

use Elysdan\EMCaptcha\Facades\EMCaptcha;

// Crear un captcha manualmente
$captcha = EMCaptcha::createFull();
// ['expression' => '7 + 3', 'answer' => 10, 'key' => 'emcaptcha_answer']

// Validar respuesta
$isValid = EMCaptcha::check($userInput);

// Refrescar captcha
$newCaptcha = EMCaptcha::refresh();

// Obtener URL de imagen
$url = EMCaptcha::getImageUrl();
bash
php artisan vendor:publish --tag=emcaptcha-config
blade
<form method="POST" action="/tu-ruta">
    @csrf

    <!-- Tus otros campos... -->

    <x-emcaptcha />

    @error('captcha')
        <span class="error">{{ $message }}</span>
    @enderror

    <button type="submit">Enviar</button>
</form>
blade
<x-emcaptcha name="mi_captcha" placeholder="Escribe el resultado" />