PHPackages                             martian/laracaptcha - 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. martian/laracaptcha

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

martian/laracaptcha
===================

A Laravel package to seamlessly use hCapthca or reCaptcha on your forms or RESTful APIs

v1.1(11mo ago)14449MITPHPPHP ^8.2CI passing

Since Jul 13Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/hendurhance/laracaptcha)[ Packagist](https://packagist.org/packages/martian/laracaptcha)[ Docs](https://github.com/hendurhance/laracaptcha)[ Fund](https://www.buymeacoffee.com/hendurhance)[ GitHub Sponsors](https://github.com/hendurhance)[ RSS](/packages/martian-laracaptcha/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (4)Versions (4)Used By (0)

LaraCaptcha
===========

[](#laracaptcha)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e4b47db941753a332eb479de90834c02e06dacc70f2eae5767516f8e3d41ab60/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d61727469616e2f6c617261636170746368612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/martian/laracaptcha)[![Total Downloads](https://camo.githubusercontent.com/a3c85d19066569c3534a1d754f9312695fe1bbe83c5941df5ec5f6a831e8d2a5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d61727469616e2f6c617261636170746368612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/martian/laracaptcha)[![GitHub Actions](https://github.com/hendurhance/laracaptcha/actions/workflows/main.yml/badge.svg)](https://github.com/hendurhance/laracaptcha/actions/workflows/main.yml/badge.svg)

A Laravel package to seamlessly integrate Google [reCAPTCHA](https://developers.google.com/recaptcha/intro) v3, v2 or [hCAPTCHA](https://www.hcaptcha.com/) into your application forms or Restful API.

 [![Image 1](https://user-images.githubusercontent.com/59781900/163660320-8209d05d-c7ed-40f3-831b-3dde16904014.png)](https://user-images.githubusercontent.com/59781900/163660320-8209d05d-c7ed-40f3-831b-3dde16904014.png) hCaptcha [![Image 2](https://cloud.githubusercontent.com/assets/1529454/5291635/1c426412-7b88-11e4-8d16-46161a081ece.gif)](https://cloud.githubusercontent.com/assets/1529454/5291635/1c426412-7b88-11e4-8d16-46161a081ece.gif) reCaptcha

Supported Captcha Services
--------------------------

[](#supported-captcha-services)

ServiceVersionTypeSupported[Google reCAPTCHA](https://developers.google.com/recaptcha/docs/v3)v3-✅ Yes[Google reCAPTCHA](https://developers.google.com/recaptcha/docs/display)v2Checkbox✅ Yes[Google reCAPTCHA](https://developers.google.com/recaptcha/docs/invisible)v2Invisible✅ Yes[hCAPTCHA](https://docs.hcaptcha.com/)-Checkbox✅ Yes[hCAPTCHA](https://docs.hcaptcha.com/invisible)-Invisible✅ YesInstallation
------------

[](#installation)

> **Note:** This package requires PHP 8.2 or higher and Laravel 11.0 or higher.

You can install the package via composer:

```
composer require martian/laracaptcha
```

Register Service Provider
-------------------------

[](#register-service-provider)

Add the following to the `providers` array in `config/app.php`:

```
Martian\LaraCaptcha\Providers\LaraCaptchaServiceProvider::class,
```

Publish Configuration File
--------------------------

[](#publish-configuration-file)

Publish the configuration file using the following command:

```
php artisan vendor:publish --provider="Martian\LaraCaptcha\Providers\LaraCaptchaServiceProvider"
```

Configuration
-------------

[](#configuration)

The configuration file is located at `config/laracaptcha.php`. The following options are available:

### reCAPTCHA v2 Configuration

[](#recaptcha-v2-configuration)

- In order to use reCAPTCHA you need to [register your site](https://www.google.com/recaptcha/admin/create) for an API key pair. To use reCaptcha v2 Checkbox, select **Challenge (v2)** **&gt;** **I'm not a robot Checkbox**. To use the invisible reCAPTCHA, select **Challenge (v2)** **&gt;** **Invisible reCAPTCHA badge**. The API key pair consists of a site key and secret key. Set the `default` option to `recaptcha` in `config/laracaptcha.php`:

    ```
    'default' => 'recaptcha',
    ```
- Change the `version` option to `v2` to use reCAPTCHA v2:

    ```
    'drivers' => [
        'recaptcha' => [
            ...
            'version' => 'v2',
            ...
        ],
    ],
    ```
- Add `RECAPTCHA_SITE_KEY` and `RECAPTCHA_SECRET_KEY` to your `.env` file:

    ```
    RECAPTCHA_SITE_KEY=your-site-key
    RECAPTCHA_SECRET_KEY=your-secret-key
    ```

### reCAPTCHA v3 Configuration

[](#recaptcha-v3-configuration)

- In order to use reCAPTCHA you need to [register your site](https://www.google.com/recaptcha/admin/create) for an API key pair. To use reCaptcha v3, select **reCAPTCHA v3**. The API key pair consists of a site key and secret key. Set the `default` option to `recaptcha` in `config/laracaptcha.php`:

    ```
    'default' => 'recaptcha',
    ```
- Change the `version` option to `v3` to use reCAPTCHA v3:

    ```
    'drivers' => [
        'recaptcha' => [
            ...
            'version' => 'v3',
            ...
        ],
    ],
    ```
- Add `RECAPTCHA_SITE_KEY`, `RECAPTCHA_SECRET_KEY` and `RECAPTCHA_SITE_URL` to your `.env` file:

    ```
    RECAPTCHA_SITE_KEY=your-site-key
    RECAPTCHA_SECRET_KEY=your-secret-key
    RECAPTCHA_SITE_URL=${APP_URL}
    ```

### hCAPTCHA Configuration

[](#hcaptcha-configuration)

- In order to use hCAPTCHA you need to [register your site](https://dashboard.hcaptcha.com/signup) for an API key pair. The API key pair consists of a site key and secret key. Set the `default` option to `hcaptcha` in `config/laracaptcha.php`:

    ```
    'default' => 'hcaptcha',
    ```
- Add `HCAPTCHA_SITE_KEY` and `HCAPTCHA_SECRET_KEY` to your `.env` file:

    ```
    HCAPTCHA_SITE_KEY=10000000-ffff-ffff-ffff-000000000001
    HCAPTCHA_SECRET_KEY=0x0000000000000000000000000000000000000000
    ```

*These are the test keys we use by default. You should not use them in production!*

Usage
-----

[](#usage)

To display captcha in your form, follow the steps below according to the captcha configuration you are using.

### reCAPTCHA v2 Checkbox &amp; Invisible

[](#recaptcha-v2-checkbox--invisible)

#### Initializing JavaScript

[](#initializing-javascript)

Add the following to the `` section of your page:

```
{!! LaraCaptcha::script() !!}
```

With other options in [Google reCaptcha v2 Checkbox dox](https://developers.google.com/recaptcha/docs/display#config)

```
{!! LaraCaptcha::script('yourCallbackFunction', 'explicit', 'en') !!}
```

*Note: The first parameter is the callback function name, the second is the rendering mode (explicit or onload), and the third is the language code from [doc](https://developers.google.com/recaptcha/docs/language)*

#### Displaying Captcha Widget - Checkbox

[](#displaying-captcha-widget---checkbox)

Add the following to your form:

```
{!! LaraCaptcha::display() !!}
```

With other options in [Google reCaptcha v2 Checkbox dox](https://developers.google.com/recaptcha/docs/display#render_param)

```
{!! LaraCaptcha::display(['data-theme' => 'dark']) !!}
```

*Note: The parameter is an array of attributes for the widget*

#### Displaying Captcha Widget - Invisible

[](#displaying-captcha-widget---invisible)

Add the following to your form:

```
{!! LaraCaptcha::displayInvisibleButton('formIdentifier', 'Submit Button',['data-size' => 'invisible']) !!}
```

*Note: The first parameter is the form identifier, the second is the button label (Submit Button), and the third is an array of attributes for the widget, see [doc](https://developers.google.com/recaptcha/docs/invisible#render_param). Add the **formIdentifier** value as the id in the form element*

#### Validating Captcha

[](#validating-captcha)

Add the following to your validation rules:

```
'g-recaptcha-response' => 'recaptcha',
```

You can also use the rule in the Validator facade:

```
$validator = Validator::make($request->all(), [
    'g-recaptcha-response' => 'recaptcha',
]);
```

#### Add Custom Validation Message

[](#add-custom-validation-message)

Add the following to your validation messages:

```
'g-recaptcha-response.recaptcha' => 'Captcha verification failed.',
```

Or you can change the default message in `config/laracaptcha.php`:

```
'error_message' => 'Captcha verification failed.',
```

### reCAPTCHA v3

[](#recaptcha-v3)

#### Initializing JavaScript

[](#initializing-javascript-1)

Add the following to the `` section of your page:

```
{!! LaraCaptcha::script() !!}
```

With other options in [Google reCaptcha v3 dox](https://developers.google.com/recaptcha/docs/v3#config)

```
{!! LaraCaptcha::script('yourCallbackFunction', 'explicit', 'en') !!}
```

#### Displaying Captcha Widget

[](#displaying-captcha-widget)

Add the following to your form:

```
{!! LaraCaptcha::display() !!}
```

With other options in [Google reCaptcha v3 dox](https://developers.google.com/recaptcha/docs/v3#render_param)

```
{!! LaraCaptcha::display(['action' => 'homepage', 'custom_validation' => 'yourCustomFunction', 'recaptcha_input_identifier' => 'yourReCaptchaInputId']) !!}
```

*Note: The parameter is an array of attributes for the widget, see [doc](https://developers.google.com/recaptcha/docs/v3#interpreting_the_score) for actions type*

### hCAPTCHA v2 Checkbox &amp; Invisible

[](#hcaptcha-v2-checkbox--invisible)

#### Initializing JavaScript

[](#initializing-javascript-2)

Add the following to the `` section of your page:

```
{!! LaraCaptcha::script() !!}
```

With other options in [hCAPTCHA dox](https://docs.hcaptcha.com/configuration)

```
{!! LaraCaptcha::script('yourCallbackFunction', 'onload', 'en', 'on') !!}
```

*Note: The first parameter is the callback function name, the second is the rendering mode (onload or explicit), the third is the language code from [doc](https://docs.hcaptcha.com/languages), and the fourth is the recaptchacompat option*

#### Displaying Captcha Widget - Checkbox

[](#displaying-captcha-widget---checkbox-1)

Add the following to your form:

```
{!! LaraCaptcha::display() !!}
```

With other options in [hCAPTCHA dox](https://docs.hcaptcha.com/configuration/#hcaptcha-container-configuration)

```
{!! LaraCaptcha::display(['data-theme' => 'dark']) !!}
```

*Note: The parameter is an array of attributes for the widget*

#### Displaying Captcha Widget - Invisible

[](#displaying-captcha-widget---invisible-1)

Add the following to your form, see documentation for [invisible hcaptcha](https://docs.hcaptcha.com/invisible):

```
{!! LaraCaptcha::displayInvisibleButton('formIdentifier', 'Submit Button',['data-size' => 'invisible']) !!}
```

*Note: The first parameter is the form identifier, the second is the button label (Submit Button), and the third is an array of attributes for the widget, see [doc](https://docs.hcaptcha.com/configuration/#hcaptcha-container-configuration)*

#### Validating Captcha

[](#validating-captcha-1)

Add the following to your validation rules:

```
'h-captcha-response' => 'hcaptcha',
```

You can also use the rule in the Validator facade:

```
$validator = Validator::make($request->all(), [
    'h-captcha-response' => 'hcaptcha',
]);
```

#### Add Custom Validation Message

[](#add-custom-validation-message-1)

Add the following to your validation messages:

```
'h-captcha-response.hcaptcha' => 'Captcha verification failed.',
```

Or you can change the default message in `config/laracaptcha.php`:

```
'error_message' => 'Captcha verification failed.',
```

For other configuration go through the `config/laracaptcha.php` file.

### Testing

[](#testing)

```
./vendor/bin/phpunit
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Josiah Endurance](https://github.com/hendurhance)

License
-------

[](#license)

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

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance51

Moderate activity, may be stable

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~728 days

Total

2

Last Release

358d ago

PHP version history (2 changes)1.0.0PHP ^7.4|^8.0

v1.1PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/50846992?v=4)[Endurance, the Martian](/maintainers/hendurhance)[@hendurhance](https://github.com/hendurhance)

---

Top Contributors

[![hendurhance](https://avatars.githubusercontent.com/u/50846992?v=4)](https://github.com/hendurhance "hendurhance (27 commits)")

---

Tags

captchadata-validationform-validationgoogle-recaptchagoogle-recaptcha-v2google-recaptcha-v3hcaptchahcaptcha-apilaravellaravel-captchalaravel-packagelaravel10laravel8laravel9phpphp8recaptcharecaptcha-apirecaptcha-v2recaptcha-v3phplaravelvalidationgooglelaravel-packagerecaptchacaptchaGoogle ReCaptchano-captcharecaptcha v3Laravel reCAPTCHAreCAPTCHA V2invisible-recaptchahcaptchamartianlaracaptcharecaptcha-v2-invisiblerecaptcha-v2-checkbox

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/martian-laracaptcha/health.svg)

```
[![Health](https://phpackages.com/badges/martian-laracaptcha/health.svg)](https://phpackages.com/packages/martian-laracaptcha)
```

###  Alternatives

[karser/karser-recaptcha3-bundle

Google ReCAPTCHA v3 for Symfony

1872.6M14](/packages/karser-karser-recaptcha3-bundle)[albertcht/invisible-recaptcha

Invisible reCAPTCHA For Laravel.

6071.6M6](/packages/albertcht-invisible-recaptcha)

PHPackages © 2026

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