PHPackages                             timehunter/laravel-google-recaptcha-v3 - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. timehunter/laravel-google-recaptcha-v3

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

timehunter/laravel-google-recaptcha-v3
======================================

Laravel Package for google reCAPTCHA v3

v2.5.3(2y ago)2821.1M↓45.5%39[12 issues](https://github.com/RyanDaDeng/laravel-google-recaptcha-v3/issues)1MITPHPPHP &gt;=5.5CI failing

Since Nov 24Pushed 2y ago5 watchersCompare

[ Source](https://github.com/RyanDaDeng/laravel-google-recaptcha-v3)[ Packagist](https://packagist.org/packages/timehunter/laravel-google-recaptcha-v3)[ Docs](https://github.com/RyanDaDeng/laravel-google-recaptcha-v3)[ RSS](/packages/timehunter-laravel-google-recaptcha-v3/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (3)Versions (86)Used By (1)

Laravel Package for Google reCAPTCHA V3
=======================================

[](#laravel-package-for-google-recaptcha-v3)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f5307edd3f67fdb6e388075e7cc716689f66b8a469c3b02191b5331c64a93d03/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f74696d6568756e7465722f6c61726176656c2d676f6f676c652d7265636170746368612d76332e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/timehunter/laravel-google-recaptcha-v3)[![Total Downloads](https://camo.githubusercontent.com/40ef260dad500649a4cd769ce570fb4ff3e9a5c662ea999379dcf5a98f5365d9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f74696d6568756e7465722f6c61726176656c2d676f6f676c652d7265636170746368612d76332e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/timehunter/laravel-google-recaptcha-v3)[![Coverage Status](https://camo.githubusercontent.com/f5221c53c265148a60fd1c5655e5cc5ab9ac8997076ad7825eab0f4970a3fbd6/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f5279616e446144656e672f6c61726176656c2d676f6f676c652d7265636170746368612d76332f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/RyanDaDeng/laravel-google-recaptcha-v3?branch=master)[![Build](https://camo.githubusercontent.com/3834161ca67156d1990672ac63080207e930c6bba5e27d22f7ccfd0aa5d66caf/68747470733a2f2f7472617669732d63692e6f72672f5279616e446144656e672f6c61726176656c2d676f6f676c652d7265636170746368612d76332e7376673f6272616e63683d6d6173746572)](https://app.travis-ci.com/github/RyanDaDeng/laravel-google-recaptcha-v3)[![StyleCI](https://camo.githubusercontent.com/92ad820e45ed82a4d0e44c342326ce26b9f4f0490f51699c59569d3ed5bcec7d/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3134363835373538332f736869656c64)](https://github.styleci.io/repos/146857583)

A star would be a nice encouragement. ^.^

Latest features:
----------------

[](#latest-features)

- Refresh Ajax supported
- Content security policy supported
- Multi lang supported
- Vue component supported
- Background mode supported

If you want to use v2, please go to:

If you only need to use Vue component, feel free to copy it.

Table of Contents
=================

[](#table-of-contents)

1. [Installation](#installation)
2. [Configurations](#settings)
3. [Facade Usage](#facade-usage)
4. [Blade Usage](#blade-basic-usage)
5. [Ajax Usage](#ajax-usage)
6. [Vue Usage](#vue-usage)
7. [Validation](#validation-class)
8. [Advanced Usage](#advanced-usage)
9. [Contributors](#contributors)

*Demo code:*

DEMO
====

[](#demo)

Invisible - hidden
------------------

[](#invisible---hidden)

[![](https://github.com/RyanDaDeng/aws-study-notes/raw/master/881545398213_.pic.jpg)](https://github.com/RyanDaDeng/aws-study-notes/blob/master/881545398213_.pic.jpg)

Inline
------

[](#inline)

[![](https://github.com/RyanDaDeng/aws-study-notes/raw/master/891545398531_.pic.jpg)](https://github.com/RyanDaDeng/aws-study-notes/blob/master/891545398531_.pic.jpg)

Corner
------

[](#corner)

[![](https://github.com/RyanDaDeng/aws-study-notes/raw/master/901545398593_.pic.jpg)](https://github.com/RyanDaDeng/aws-study-notes/blob/master/901545398593_.pic.jpg)

Description
-----------

[](#description)

Google reCAPTCHA v3 is a new mechanism to verify whether the user is bot or not.

reCAPTCHA v3 is intended for power users, site owners that want more data about their traffic, and for use cases in which it is not appropriate to show a challenge to the user.

For example, a registration page might still use reCAPTCHA v2 for a higher-friction challenge, whereas more common actions like sign-in, searches, comments, or voting might use reCAPTCHA v3.

Please check Google site:

Features
--------

[](#features)

- High Test coverage, safe and easy to use
- Score Comparison
- Support invisible, corner and inline badge style
- Support reCAPTCHA to run on every page
- Support multiple actions to be placed on the same page
- Support custom implementation on config interface
- Support custom implementation on request method interface
- Fully supported Vue component
- IP skip list supported

Requirement
-----------

[](#requirement)

This package requires the following dependencies:

- Laravel &gt;= 5.x
- If you want to use Validation Class your Laravel version needs to be &gt;= 5.5
- php &gt; 5
- Please ensure that you have read basic information from Google reCAPTCHA v3.

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

[](#installation-)

*Demo code:*

Via Composer

```
$ composer require timehunter/laravel-google-recaptcha-v3 "~2.5"
```

If your Laravel framework version &lt;= 5.4, please register the service provider under your config file: /config/app.php, otherwise please skip it.

```
'providers'=[
    ....,
    TimeHunter\LaravelGoogleReCaptchaV3\Providers\GoogleReCaptchaV3ServiceProvider::class
]
```

And also

```
'aliases'=[
     ....,
     'GoogleReCaptchaV3'=> TimeHunter\LaravelGoogleReCaptchaV3\Facades\GoogleReCaptchaV3::class
 ]
```

If your Laravel framework version is &gt;= 5.5, just run the following command to publish config.

```
$ php artisan vendor:publish --provider="TimeHunter\LaravelGoogleReCaptchaV3\Providers\GoogleReCaptchaV3ServiceProvider" --tag=googlerecaptchav3.config
```

For vue component:

```
$ php artisan vendor:publish --provider="TimeHunter\LaravelGoogleReCaptchaV3\Providers\GoogleReCaptchaV3ServiceProvider" --tag=googlerecaptchav3.vuejs
```

After installation, you should see a googlerecaptchav3.php in your app/config folder, and vue component under js/components/googlerecaptchav3 folder.

For multi lang:

```
$ php artisan vendor:publish --provider="TimeHunter\LaravelGoogleReCaptchaV3\Providers\GoogleReCaptchaV3ServiceProvider" --tag=googlerecaptchav3.lang
```

A lang folder will be created under /resources/lang/vendor/GoogleReCaptchaV3/\*

Configurations
---------------------------------------------------

[](#configurations-)

### Setting up your Google reCAPTCHA details in config file

[](#setting-up-your-google-recaptcha-details-in-config-file)

Please register all details in config for host\_name, site\_key, secret\_key and site\_verify\_url.

Register credentials in .env:

```
RECAPTCHA_V3_SECRET_KEY=
RECAPTCHA_V3_SITE_KEY=

```

Specify your Score threshold and action in 'setting', e.g.

```
      'setting' =  [
          [
                'action' => 'contact_us', // Google reCAPTCHA required paramater
                'threshold' => 0.2, // score threshold
                'score_comparison' => false // if this is true, the system will do score comparsion against your threshold for the action
            ],
            [
                'action' => 'signup',
                'threshold' => 0.2,
                'score_comparison' => true
            ],
        ]
```

Note: if you want to enable Score Comparison, you also need to enable is\_score\_enabled to be true.

```
        ...
        'is_score_enabled' = true
        ...
```

For score comparison, all actions should be registered in googlerecaptchav3 config file under 'setting' section.

For more details please check comments in config file.

Facade Usage
-----------------------------------------------------

[](#facade-usage-)

You can directly use registered facade service by calling the following methods.

- setAction() is optional only if you want to verify if the action is matched.
- verifyResponse() which accepts the token value from your form. This returns Google reCAPTCHA Response object.
- setScore() is optional only if you want to manually verify the score.

Example Usage

```
   GoogleReCaptchaV3::setAction($action)->verifyResponse($value,$ip = null);
```

```
   GoogleReCaptchaV3::verifyResponse($value,$ip)->getMessage();
   GoogleReCaptchaV3::verifyResponse($value)->isSuccess();
   GoogleReCaptchaV3::verifyResponse($value)->toArray();
```

```
   GoogleReCaptchaV3::verifyResponse(
                         $request->input('g-recaptcha-response'),
                         $request->getClientIp()
                         )
                      ->getMessage()
```

```
   GoogleReCaptchaV3::setAction($action)->verifyResponse($value)->isSuccess();
```

If you manually assign a value to setScore($score), the code will fully skip your config file and force to check the score.

```
   GoogleReCaptchaV3::setScore($score)
                    ->setAction($action)
                    ->verifyResponse(
                        $request->input('g-recaptcha-response'),
                        $request->getClientIp()
                        )
                    ->getMessage()
```

Validation Class (Only support Laravel &gt;= 5.5)
----------------------------------------------------------------------------------------------

[](#validation-class-only-support-laravel--55-)

You can use provided Validation object to verify your reCAPTCHA.

```
   use TimeHunter\LaravelGoogleReCaptchaV3\Validations\GoogleReCaptchaV3ValidationRule;
   $rule = [
            'g-recaptcha-response' => [new GoogleReCaptchaV3ValidationRule('action_name')]
        ];
```

- $actionName: if its NULL, the package won't verify action with google response.

Blade Usage
---------------------------------------------------------

[](#blade-usage-)

### Display reCAPTCHA v3

[](#display-recaptcha-v3)

#### Add Google API script

[](#add-google-api-script)

Include the API script at the bottom of your layout page

```
  {!!  GoogleReCaptchaV3::init() !!}
```

##### Consent Security Policy - Nonce

[](#consent-security-policy---nonce)

To add a nonce for content security, pass a params array with your pages nonce.

```
  {!!  GoogleReCaptchaV3::init([
    'nonce' => nonce(),
  ]) !!}
```

#### Running script on every page (optional)

[](#running-script-on-every-page-optional)

It's recommended to include reCAPTCHA v3 on every page which can help you get the most context about interactions for analytics. You just need to enable the config:

```
   ...
  'background_badge_display' => true, // if false, the badge will be invisible, if true the badge shows at bottom right.
  'background_mode' => false, // if true, the script will run on every page (ensure that GoogleReCaptchaV3::init() is placed on layout or homepage)
   ...
```

If the page has not detected any Action or duplicate google script, the background mode will be enabled.

#### Form &amp; Action

[](#form--action)

There are three methods to populate the reCAPTCHA within the form.

- render() and renderOne() can be placed in anywhere but before init()
- renderField() needs always to be placed within your form.

Method one - render():

```
[
    $id=>$action , $id=>$action ...
]

{!!  GoogleReCaptchaV3::render(['contact_us_id'=>'contact_us', 'signup_id'=>'signup']) !!}

```

```

     // add div with id

{!!  GoogleReCaptchaV3::render(['contact_us_id'=>'contact_us', 'signup_id'=>'signup']) !!}
```

Method two - renderOne():

```
GoogleReCaptchaV3::renderOne($id,$action);

{!!  GoogleReCaptchaV3::renderOne('contact_us_id','contact_us') !!}

```

```

     // add div with id

{!!  GoogleReCaptchaV3::renderOne('contact_us_id','contact_us') !!}
```

Method three - renderField():

```
GoogleReCaptchaV3::renderField($id,$action,$class,$style)

{!! GoogleReCaptchaV3::renderField('contact_us_id','contact_us_action') !!}

```

```

   {!!  GoogleReCaptchaV3::renderField('contact_us_id','contact_us_action') !!}

```

### Badge Display for Form &amp; Action

[](#badge-display-for-form--action)

If your settings were not reflected, please run php artisan config:cache to clear cache.

Inline

1. Go to config file, and set

```
    [
        ...
        'inline' => true
        ...
    ]
```

2. Badge will be displayed as inline format within the form.

Invisible

1. Set inline as true as well
2. Modify your div with style display:none
3. Refer to Google official site: , you need to include the following text:

```
   This site is protected by reCAPTCHA and the Google
       Privacy Policy and
       Terms of Service apply.
```

Corner

1. Set inline as false
2. Your badge will be shown in the bottom right side.

Custom

1. Set inline as true
2. Do Styling/CSS on its div element

### Ajax Usage - Refresh reCAPTCHA Response

[](#ajax-usage---refresh-recaptcha-response-)

The package provides two handy Javascript functions for you to get recaptcha response and refresh recaptcha as needed.

- refreshReCaptchaV3(fieldId,actionName) - this function will reset the response whenever your ajax response is returned.
- getReCaptchaV3Response - this function helps you to get recaptcha response by id

For example:

```

            $("#test").click(function (e) {
                e.preventDefault();
                $.ajax({
                    type: 'POST',
                    url: '/verify',
                    data: {
                        'g-recaptcha-response':getReCaptchaV3Response('contact_id')
                    },
                    success: function (data) {
                        refreshReCaptchaV3('contact_id','contact');
                    },
                    error: function(err){
                        refreshReCaptchaV3('contact_id','contact');
                    }
                });
            });

```

Vue Usage (Package version &gt;= 2.2.0)
-----------------------------------------------------------------------------

[](#vue-usage-package-version--220-)

The package provides a lightweight vue component. You need to publish the vue component before playing around it.

### Step 1 Publish vue component:

[](#step-1-publish-vue-component)

```
$ php artisan vendor:publish --provider="TimeHunter\LaravelGoogleReCaptchaV3\Providers\GoogleReCaptchaV3ServiceProvider" --tag=googlerecaptchav3.vuejs
```

The file will be created under js/components/googlerecaptchav3/GoogleReCaptchaV3.vue, you have full control and modification ability on this file.

### Step 2 Import vue component and Register reCAPTCHA v3 SiteKey

[](#step-2-import-vue-component-and-register-recaptcha-v3-sitekey)

#### A BIG thanks to [@Fluxlicious](https://github.com/Fluxlicious) who improved the vue component.

[](#a-big-thanks-to-fluxlicious-who-improved-the-vue-component)

The Blade way is no longer useful if you use Vue. We need to manage to assign site key by ourselves. The component supports props below:

Supported: siteKey, id, inline and action, check the original file to see the details.

```

```

There are two ways you can bind site key to the component.

### Use prop

[](#use-prop)

```

            Submit

    import GoogleReCaptchaV3 from '../../components/googlerecaptchav3/GoogleReCaptchaV3';
    // location might be diff to your case, ensure that your component location is right

    export default {
        components: {
            GoogleReCaptchaV3
        },
        data() {
            return {
                form: {
                    gRecaptchaResponse: null
                },
                mySiteKeyVariable: 'Your Site Key String',
            }
        },
        methods: {
            submit() {
                axios.post('/verify', this.form).then(
                    response => {
                        this.$refs.captcha.execute(); // every time you submit, the reCAPTCHA token needs to be refreshed
                    }
                ).catch(
                    error => {
                        this.$refs.captcha.execute(); // every time you submit, the reCAPTCHA token needs to be refreshed
                    });
            }
        }
    }

```

Please remember to refresh token every time you submit the form if needed:

```
 this.$refs.captcha.execute();
```

### or Add site key directly into GoogleReCaptchaV3 component

[](#or-add-site-key-directly-into-googlerecaptchav3-component)

Alternatively, I believe most of cases your site key will never be changed, so you could just modify the original published component to have sitekey hard-coded in.

For instance, open published file and find code below:

```
        ....
        siteKey: {
                  type: String,
                  required: false, // set to true if you don't want to store the siteKey in this component
                  default: 'Your Site Key Here' // set siteKey here if you want to store it in this component
              },
       ....
```

Advanced Usage
---------------------------------------------------------

[](#advanced-usage-)

### Custom implementation on Config

[](#custom-implementation-on-config)

For some users, they might store the config details in their own storage e.g database. You can create your own class and implement:

```
TimeHunter\LaravelGoogleReCaptchaV3\Interfaces\ReCaptchaConfigV3Interface

```

Remember to register it in your own service provider

```
     $this->app->bind(
                ReCaptchaConfigV3Interface::class,
                YourOwnCustomImplementation::class
            );
```

### Custom implementation on Request method

[](#custom-implementation-on-request-method)

The package has two default options to verify: Guzzle and Curl, if you want to use your own request method, You can create your own class and implement

```
TimeHunter\LaravelGoogleReCaptchaV3\Interfaces\RequestClientInterface

```

Remember to register it in your own service provider

```
     $this->app->bind(
                RequestClientInterface::class,
                YourOwnCustomImplementation::class
            );
```

Contributors
-----------------------------------------------------

[](#contributors--)

Thank you for the following contributors, You guys are the BEST!

- [@xalunda](https://github.com/xalunda)
- [@Fluxlicious](https://github.com/Fluxlicious)
- [@vinsonyung](https://github.com/vinsonyung)
- [@demiurge-ash](https://github.com/demiurge-ash)
- [@lxlang](https://github.com/lxlang)
- [@Indianos](https://github.com/Indianos)
- [@ericp-mrel](https://github.com/ericp-mrel)
- [@QuentinBontemps](https://github.com/QuentinBontemps)
- [@alr2413](https://github.com/alr2413)

Security
--------

[](#security)

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

License
-------

[](#license)

MIT. Please see the [license file](license.md) for more information.

###  Health Score

48

—

FairBetter than 93% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity58

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 96.8% 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 ~32 days

Recently: every ~257 days

Total

64

Last Release

756d ago

Major Versions

0.2.0 → 1.0.02018-11-24

1.3.1 → 2.0.02018-12-25

PHP version history (2 changes)0.1.0PHP &gt;=5.5

0.1.4PHP &gt;=7.1.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/23565942?v=4)[timehunter](/maintainers/timehunter)[@Timehunter](https://github.com/Timehunter)

---

Top Contributors

[![RyanDaDeng](https://avatars.githubusercontent.com/u/37111049?v=4)](https://github.com/RyanDaDeng "RyanDaDeng (448 commits)")[![xalunda](https://avatars.githubusercontent.com/u/2316221?v=4)](https://github.com/xalunda "xalunda (3 commits)")[![Fluxlicious](https://avatars.githubusercontent.com/u/8587776?v=4)](https://github.com/Fluxlicious "Fluxlicious (2 commits)")[![Weisskpub](https://avatars.githubusercontent.com/u/6427260?v=4)](https://github.com/Weisskpub "Weisskpub (2 commits)")[![ldommer](https://avatars.githubusercontent.com/u/65616313?v=4)](https://github.com/ldommer "ldommer (1 commits)")[![alr2413](https://avatars.githubusercontent.com/u/10116275?v=4)](https://github.com/alr2413 "alr2413 (1 commits)")[![Machecek](https://avatars.githubusercontent.com/u/3853689?v=4)](https://github.com/Machecek "Machecek (1 commits)")[![QuentinBontemps](https://avatars.githubusercontent.com/u/4568504?v=4)](https://github.com/QuentinBontemps "QuentinBontemps (1 commits)")[![luisrossi](https://avatars.githubusercontent.com/u/53585086?v=4)](https://github.com/luisrossi "luisrossi (1 commits)")[![demiurge-ash](https://avatars.githubusercontent.com/u/40300551?v=4)](https://github.com/demiurge-ash "demiurge-ash (1 commits)")[![Indianos](https://avatars.githubusercontent.com/u/35456491?v=4)](https://github.com/Indianos "Indianos (1 commits)")[![juliangeissler](https://avatars.githubusercontent.com/u/81534590?v=4)](https://github.com/juliangeissler "juliangeissler (1 commits)")

---

Tags

google-recaptchagoogle-recaptcha-v3googlerecaptchalaravel-google-recaptchalaravel-recaptchalaravel-recaptcha-v3recaptcharecaptcha-laravelrecaptcha-v3recaptcha-v3-laravelvue-recaptchavue-recaptcha-v3laravelrecaptchaGoogle ReCaptcharecaptcha v3GoogleReCaptchagoogle recaptcha v3Laravel reCAPTCHAlaravel google recaptcha v3laravel google recaptcharecaptcha v3 laravellaravel recaptcha v3

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/timehunter-laravel-google-recaptcha-v3/health.svg)

```
[![Health](https://phpackages.com/badges/timehunter-laravel-google-recaptcha-v3/health.svg)](https://phpackages.com/packages/timehunter-laravel-google-recaptcha-v3)
```

###  Alternatives

[timehunter/laravel-google-recaptcha-v2

Laravel Package for google reCAPTCHA v2

13102.7k](/packages/timehunter-laravel-google-recaptcha-v2)[karser/karser-recaptcha3-bundle

Google ReCAPTCHA v3 for Symfony

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

Laravel package for Google Recaptcha v3

2128.2k](/packages/mostafaznv-recaptcha)[anam/captcha

reCAPTCHA and invisible reCAPTCHA for Laravel. reCAPTCHA protects your app against spam and bot.

2944.7k](/packages/anam-captcha)[dutchcodingcompany/livewire-recaptcha

Add Google Recaptcha V3 support to your Laravel Livewire components

2533.0k4](/packages/dutchcodingcompany-livewire-recaptcha)

PHPackages © 2026

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