All Projects → huangdijia → laravel-recaptcha-v3

huangdijia / laravel-recaptcha-v3

Licence: MIT license
recaptcha-v3 for laravel

Programming Languages

PHP
23972 projects - #3 most used programming language
Blade
752 projects

Google reCaptcha v3 for Laravel 5.6+

Latest Test Latest Stable Version Total Downloads GitHub license

Installation

To install, simply add it to your composer.json file:

{
    "require": {
        "huangdijia/laravel-recaptcha-v3": "^2.0"
    }
}

And run composer to update your dependencies:

composer update

Or you can simply run

composer require huangdijia/laravel-recaptcha-v3

Publish configuration file to your config folder with command:

php artisan vendor:publish --provider="Huangdijia\Recaptcha\RecaptchaServiceProvider" --tag=config

Usage

Forms

// default
@recaptcha_field()

// custom
@recaptcha_field(['site_key'=>'your_key', 'name'=>'input_name'])

Init Recaptcha Javascript

Must add after @recaptcha_field()

Recaptcha v3 works best when it is loaded on every page to get the most context about interactions. Therefore, add to your header or footer template:

// default
@recaptcha_initjs()

// custom
@recaptcha_initjs(['site_key'=>'your_key', 'action' => 'action_name', 'name'=>'input_name'])

Validation as regular validation rule

Use as regular validation rule recaptcha:{ACTION},{SCORE},{HOSTNAME} like:

Validator::make($request->all(), [
    'g-recaptcha-response' => 'required|recaptcha:register,0.5,www.a.com',
    // or
    // 'g-recaptcha-response' => 'required|recaptcha',
]);

Validation as middleware

Set $routeMiddleware

    $routeMiddleware = [
        // ...
        'recaptcha' => Huangdijia\Recaptcha\Middleware\ReCaptcha::class,
    ];

Use with route

Route::get('/path')->middleware('recaptcha');
Route::get('/path')->middleware('recaptcha:{ACTION},{SCORE},{HOSTNAME}');
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].