PHP code example of dev-3bdulrahman / laravel-captcha

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

    

dev-3bdulrahman / laravel-captcha example snippets


use Illuminate\Http\Request;

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

// config/captcha.php
'image' => [
    'use_svg' => true, // Enable SVG format
    // ... other settings
],

use Dev3bdulrahman\LaravelCaptcha\Facades\Captcha;

// Generate captcha
$data = Captcha::generate('image', 'medium');

// Verify captcha
$isValid = Captcha::verify($input, 'image');

// Refresh captcha
Captcha::refresh('image');

// Get captcha data
$data = Captcha::getData('image');

use Dev3bdulrahman\LaravelCaptcha\Facades\Captcha;

if (Captcha::verify($request->input('captcha'), 'image')) {
    // Captcha is valid
} else {
    // Captcha is invalid
}

return [
    // Default captcha type
    'default' => 'image',
    
    // Default difficulty level
    'difficulty' => 'medium',
    
    // Session key for storing captcha
    'session_key' => 'laravel_captcha',
    
    // Expiration time in minutes
    'expire' => 5,
    
    // Image captcha settings
    'image' => [
        'width' => 200,
        'height' => 60,
        'length' => [
            'easy' => 4,
            'medium' => 5,
            'hard' => 6,
        ],
        // ... more settings
    ],
    
    // Math captcha settings
    'math' => [
        'operators' => [
            'easy' => ['+', '-'],
            'medium' => ['+', '-', '*'],
            'hard' => ['+', '-', '*', '/'],
        ],
        // ... more settings
    ],
    
    // ... other settings
];

'text' => [
    'questions' => [
        'easy' => [
            'Your question?' => 'answer',
            // Add more questions
        ],
    ],
],
bash
php artisan vendor:publish --tag=captcha-config
bash
php artisan vendor:publish --tag=captcha-assets
bash
php artisan vendor:publish --tag=captcha-views
blade
<form method="POST" action="/submit">
    @csrf
    
    <!-- Your form fields -->
    
    @
bash
php artisan vendor:publish --tag=captcha-views
blade
<form method="POST" action="{{ route('register') }}">
    @csrf
    
    <!-- Registration fields -->
    
    @e="submit">Register</button>
</form>