PHP code example of origami / captcha

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

    

origami / captcha example snippets


    
    'recaptcha' => [
        'key' => env('RECAPTCHA_KEY'),
        'secret' => env('RECAPTCHA_SECRET'),
    ],


$validator = Validator::make($request->all(), [
    'recaptcha' => [new Origami\Captcha\Rules\Recaptcha],
]);

class Contact extends Controller
{
    public function store(Request $request)
    {
        $this->validate($request, [
            'recatpcha' => [new Origami\Captcha\Rules\Recaptcha]
        ]);
    }
}

class Contact extends Controller
{
    public function store(Request $request)
    {
        $this->validate($request, [
            'recatpcha' => [new Origami\Captcha\Rules\Recaptcha(secret: '123')]
        ]);
    }
}


use Origami\Captcha\ValidatesCaptcha;

class Contact extends Controller
{
    use ValidatesCaptcha;

    public function store(Request $request)
    {
        $this->validateRecaptcha($request);

        // The above will throw a ValidationException when the recaptcha fails.
    }

}

// Before
$validator = Validator::make($request->all(), [
    'recaptcha' => 'recaptcha',
]);

// After
$validator = Validator::make($request->all(), [
    'recaptcha' => [new Origami\Captcha\Rules\Recaptcha],
]);