felipetti/captcha

This package is for integrating captcha service to Laravel project

v2.0.4 2024-04-12 22:31 UTC

This package is auto-updated.

Last update: 2024-04-12 22:33:56 UTC


README

What it does:

This package allows you to integrate CAPTCHA V2 or V3 to your Laravel application.

Installation:

composer require felipetti/captcha

Usage instructions:

First you publish config file:

php artisan vendor:publish --tag=captcha

Config file named captcha.php is published in config folder of root directory. Open the file and put the secret key provided by Google inside "secret_key" field.

/*
    |--------------------------------------------------------------------------
    | Secret Key
    |--------------------------------------------------------------------------
    |
    | This is the CAPTCHA key that only back-end has.
    |
    */

    'secret_key' => ''

There are three ways of captcha service integration, assuming $captcha is the field where front-end sends captcha response:

Form request way:

    use Felipetti\Captcha\Rule\CaptchaVerification;
    
    public function rules()
    {
        $captcha = ['required', 'string', new CaptchaVerification];
        
        return compact('captcha');
    }

Request validation way:

Let's suppose we have a captcha controller, and we want to make validation inside:

use Felipetti\Captcha\Rule\CaptchaVerification;
use Illuminate\Http\Request;

class CaptchaController extends Controller
{
    public function __invoke(Request $request)
    {
        $request->validate(
            ['captcha' => [new CaptchaVerification]]
        );

        //...
    }
}

Validator way:

use Felipetti\Captcha\Rule\CaptchaVerification;
use Illuminate\Support\Facades\Validator;
use Illuminate\Http\Request;

class CaptchaController extends Controller
{
    public function __invoke(Request $request)
    {
        $rules  = ['captcha' => [new CaptchaVerification]];

        Validator::make($request->only('captcha'), $rules)->validate();

        //...
    }
}

Config:

Explanations in config file are quite expressive, so if you have any questions, please email guill388@hotmail.com.

Comments:

Please star me if you liked the package, it will really help me a lot.

Security:

If you discover any security-related issues, please e-mail me to the one above instead of using the issue tracker.

License:

The MIT License (MIT).