PHPackages                             nguyendachuy/laravel-recaptcha3 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. nguyendachuy/laravel-recaptcha3

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

nguyendachuy/laravel-recaptcha3
===============================

This library provides support for Google reCAPTCHA v3 in Laravel. This library makes it easy to add reCAPTCHA to your Laravel application to protect against spam and bots.

v1.0.1(11mo ago)039PHPPHP &gt;=7.0.0

Since Dec 7Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/nguyendachuy/laravel-recaptcha3)[ Packagist](https://packagist.org/packages/nguyendachuy/laravel-recaptcha3)[ Docs](https://github.com/nguyendachuy/laravel-recaptcha3)[ RSS](/packages/nguyendachuy-laravel-recaptcha3/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

Google reCAPTCHA v3 in Laravel
==============================

[](#google-recaptcha-v3-in-laravel)

This library provides support for Google reCAPTCHA v3 in Laravel. This library makes it easy to add reCAPTCHA to your Laravel application to protect against spam and bots.

[![Latest Stable Version](https://camo.githubusercontent.com/70684148ed0c2ab0ab4b04509a592ec2e9f431abe6bbe0cc546bebfe53735def/68747470733a2f2f706f7365722e707567782e6f72672f6e677579656e6461636875792f6c61726176656c2d726563617074636861332f76)](//packagist.org/packages/nguyendachuy/laravel-recaptcha3) [![Total Downloads](https://camo.githubusercontent.com/9561a432773c3cf099bf86bb26aeb5732251cec09780f65deaabec2696404b42/68747470733a2f2f706f7365722e707567782e6f72672f6e677579656e6461636875792f6c61726176656c2d726563617074636861332f646f776e6c6f616473)](//packagist.org/packages/nguyendachuy/laravel-recaptcha3) [![Latest Unstable Version](https://camo.githubusercontent.com/6f9c617b9249672efa28cade59d143e96aeee650178ddea551c633265b175f56/68747470733a2f2f706f7365722e707567782e6f72672f6e677579656e6461636875792f6c61726176656c2d726563617074636861332f762f756e737461626c65)](//packagist.org/packages/nguyendachuy/laravel-recaptcha3) [![License](https://camo.githubusercontent.com/df81659fb9cf6be6bfb3dd63c33f08afdbeb92bf94cc755920989bae3d7b43c1/68747470733a2f2f706f7365722e707567782e6f72672f6e677579656e6461636875792f6c61726176656c2d726563617074636861332f6c6963656e7365)](//packagist.org/packages/nguyendachuy/laravel-recaptcha3)

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Blade Directives](#blade-directive)
    - [Form Integration](#form-integration)
    - [Validation](#validation)
    - [Using the Facade](#using-the-facade)
- [Advanced Features](#advanced-features)
    - [Auto Token Refresh](#auto-token-refresh)
    - [Error Handling](#error-handling)
    - [Custom Attributes](#custom-attributes)
    - [Action-specific Validation](#action-specific-validation)
- [Changelog](#changelog)
- [Credits](#credits)
- [License](#license)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require nguyendachuy/laravel-recaptcha3
```

You can publish config file with:

```
php artisan vendor:publish --tag="recaptcha-config"
```

This is the contents of the published config file:
--------------------------------------------------

[](#this-is-the-contents-of-the-published-config-file)

```
return [
    /*
    |--------------------------------------------------------------------------
    | The reCAPTCHA site key provided by Google
    |--------------------------------------------------------------------------
    |
    | Here you can set the sitekey
    */

    'sitekey' => env('GOOGLE_CAPTCHA_SITEKEY', null),

    /*
    |--------------------------------------------------------------------------
    | The reCAPTCHA secret key provided by Google
    |--------------------------------------------------------------------------
    |
    | Here you can set the secet
    */

    'secret' => env('GOOGLE_CAPTCHA_SECRET', null)
];
```

References
----------

[](#references)

Google reCAPTCHA documentation:

Usage
-----

[](#usage)

### Using the Facade

[](#using-the-facade)

You can also use the `Recaptcha` facade directly in your controllers or other classes:

```
use NguyenHuy\Recaptcha\Facades\Recaptcha;

class ContactController extends Controller
{
    public function store(Request $request)
    {
        // Verify the token
        $token = $request->input('g-recaptcha-response');
        $ip = $request->ip();
        $action = 'contact_form';
        $minScore = 0.5;

        $result = Recaptcha::verify($token, $ip, [$action, $minScore]);

        if (!$result) {
            return back()->withErrors(['captcha' => 'reCAPTCHA verification failed']);
        }

        // Process form submission
        // ...
    }
}
```

### Blade directive

[](#blade-directive)

This directive imports the recaptcha JavaScript library and configures it with your site key.

```

    {{-- your app --}}

    {{-- Default action is "form" --}}
    @recaptchaJs

    {{-- or custom action --}}
    @recaptchaJs('form')

```

Use on the form

```

    {{-- your input --}}

    {{-- Default name is "g-recaptcha-response" --}}
    @recaptchaInput

    {{-- or custom name --}}
    @recaptchaInput('custom-name')

    {{-- with custom attributes and action --}}
    @php
        $attributes = ['data-form' => 'contact'];
        $action = 'contact_form';
        $name = 'g-recaptcha-response';
    @endphp
    @recaptchaInput($name)

```

Use on the validator

```
$request->validate([
    'g-recaptcha-response' => 'captcha'
]);
```

Optimizing Views

```
php artisan view:clear
```

Credits
-------

[](#credits)

- [NguyenDacHuy](https://github.com/nguyendachuy)
- [All Contributors](../../contributors)

Advanced Features
-----------------

[](#advanced-features)

### Auto Token Refresh

[](#auto-token-refresh)

reCAPTCHA tokens expire after 2 minutes. This library now automatically refreshes tokens every 90 seconds to ensure your forms always have valid tokens.

### Error Handling

[](#error-handling)

Improved error handling with detailed logging when verification fails, making it easier to debug issues.

### Custom Attributes

[](#custom-attributes)

You can now add custom HTML attributes to the reCAPTCHA input field:

```
$attributes = ['data-form' => 'contact', 'class' => 'recaptcha-input'];
$captcha = new \NguyenHuy\Recaptcha\CaptchaV3();
$display = $captcha->display('g-recaptcha-response', $attributes);
```

### Action-specific Validation

[](#action-specific-validation)

You can specify different actions for different forms and validate them accordingly:

```
// In your form
@php
    $action = 'contact_form';
@endphp
@recaptchaInput('g-recaptcha-response')

// In your controller
$request->validate([
    'g-recaptcha-response' => 'captcha:contact_form,0.7'
]);
```

Changelog
---------

[](#changelog)

### v1.1.0 (2025-05-26)

[](#v110-2025-05-26)

- Added auto token refresh to prevent token expiration
- Improved error handling with detailed logging
- Added support for custom HTML attributes
- Fixed Facade binding issue
- Added support for action-specific validation
- Enhanced security with proper input sanitization

### v1.0.0 (2023)

[](#v100-2023)

- Initial release

Support
-------

[](#support)

Please feel free to contact me if you find any bug or create an issue for that!.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance50

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 80% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~535 days

Total

2

Last Release

352d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/51a37c190ab4fecfeb65c235b1922b254b42e3f063bd1c5c4d48a76833dad5ba?d=identicon)[huy.cit](/maintainers/huy.cit)

---

Top Contributors

[![nguyendachuy](https://avatars.githubusercontent.com/u/15666602?v=4)](https://github.com/nguyendachuy "nguyendachuy (4 commits)")[![obiihuy](https://avatars.githubusercontent.com/u/155449672?v=4)](https://github.com/obiihuy "obiihuy (1 commits)")

---

Tags

laravelrecaptchaform validationGoogle ReCaptcharecaptcha v3Laravel reCAPTCHA

### Embed Badge

![Health badge](/badges/nguyendachuy-laravel-recaptcha3/health.svg)

```
[![Health](https://phpackages.com/badges/nguyendachuy-laravel-recaptcha3/health.svg)](https://phpackages.com/packages/nguyendachuy-laravel-recaptcha3)
```

###  Alternatives

[timehunter/laravel-google-recaptcha-v3

Laravel Package for google reCAPTCHA v3

2861.0M1](/packages/timehunter-laravel-google-recaptcha-v3)[karser/karser-recaptcha3-bundle

Google ReCAPTCHA v3 for Symfony

1862.4M7](/packages/karser-karser-recaptcha3-bundle)[timehunter/laravel-google-recaptcha-v2

Laravel Package for google reCAPTCHA v2

1395.4k](/packages/timehunter-laravel-google-recaptcha-v2)[mostafaznv/recaptcha

Laravel package for Google Recaptcha v3

2127.5k](/packages/mostafaznv-recaptcha)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
