PHPackages                             vlinde/recaptcha - 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. vlinde/recaptcha

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

vlinde/recaptcha
================

Laravel package for Google Recaptcha v3

2.0.1(3y ago)01.4kMITPHPPHP &gt;=5.6.4

Since Nov 8Pushed 3y agoCompare

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

READMEChangelogDependencies (2)Versions (10)Used By (0)

Laravel Recaptcha v3
====================

[](#laravel-recaptcha-v3)

Laravel package for [Google Recaptcha v3](https://developers.google.com/recaptcha/docs/v3)

Some of the features for Recaptcha:
-----------------------------------

[](#some-of-the-features-for-recaptcha)

- Configurable and Customizable
- Callback function
- Service Container
- Auto discovery (only laravel 5.5+)

Requirements:
-------------

[](#requirements)

- Laravel 5.3 or higher
- PHP 5.6.4 or higher

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

[](#installation)

1. ##### Install the package via composer:

    [](#install-the-package-via-composer)

    ```
    composer require mostafaznv/recaptcha
    ```
2. ##### Register Provider and Facade in config/app.php (Required for Laravel 5.3 and 5.4):

    [](#register-provider-and-facade-in-configappphp-required-for-laravel-53-and-54)

    ```
    'providers' => [
      ...
      Mostafaznv\Recaptcha\RecaptchaServiceProvider::class,
    ],

    'aliases' => [
      ...
      'Recaptcha' => Mostafaznv\Recaptcha\Facades\Recaptcha::class,
    ]
    ```
3. ##### Publish config and views:

    [](#publish-config-and-views)

    ```
    php artisan vendor:publish --provider="Mostafaznv\Recaptcha\RecaptchaServiceProvider"
    ```
4. ##### Done

    [](#done)

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

[](#configuration)

Add `RECAPTCHA_SITE_KEY` and `RECAPTCHA_SECRET_KEY` to `.env` file:

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

to set more, open config/recaptcha.php and set your own configurations.

```
return [
    'secret_key' => env('RECAPTCHA_SECRET_KEY'),
    'site_key'   => env('RECAPTCHA_SITE_KEY'),

    'is_active' => true,

    'score' => 0.5,

    'options' => [
        'timeout' => 5.0,
    ]
];
```

Usage
-----

[](#usage)

1. ##### Render JS

    [](#render-js)

    ```
    {!! Recaptcha::renderJs() !!}
    ```
2. ##### Create Recaptcha field

    [](#create-recaptcha-field)

    this is a hidden input field that gets filled with a recaptcha token.

    ```
    {!! Recaptcha::field('login') !!}
    ```
3. ##### Validate

    [](#validate)

    ```
    $validate = Validator::make(Input::all(), [
       'g-recaptcha-response' => 'required|recaptcha:login'
    ]);
    ```
4. ##### Done

    [](#done-1)

Custom Validation Message
-------------------------

[](#custom-validation-message)

Add the following values to the `custom` array in the `validation` language file:

```
'custom' => [
    'g-recaptcha-response' => [
        'required' => 'Please verify that you are not a robot.',
        'recaptcha' => 'Captcha error! try again later or contact site admin.',
    ],
],
```

Then check for captcha errors in the Form:

```
@if ($errors->has('g-recaptcha-response'))
    {{ $errors->first('g-recaptcha-response') }}
@endif
```

Validate Score Manually
-----------------------

[](#validate-score-manually)

Alternatively, you can get the score and take variable action:

```
$token = $request->get('g-recaptcha-response');
$action = 'home';
$score = 0;

$score = app('recaptcha')->verify($token, $action, $score);

if($score > 0.7) {
    // is valid
}
else if($score > 0.3) {
    // require additional email verification
}
else {
    return abort(400, 'Bad request');
}
```

Methods
-------

[](#methods)

#### RenderJs

[](#renderjs)

Argument IndexArgument NameDefaultExampleTypeDescription0languagenullfastring#### Field

[](#field)

Argument IndexArgument NameDefaultExampleTypeDescription0actionhomestringName of your action1nameg-recaptcha-responserecaptcha\_fieldstringValue of name attribute for hidden file input2attributes\[\]\['id' =&gt; 'recaptcha-id', 'class' =&gt; 'form-element', 'required'\]arrayArray of attributes to render inside input field3callbacknullrecaptchaCallbackstringSometimes you want to use token with js. package will send token to your callback function#### Validation

[](#validation)

Argument IndexArgument NameDefaultExampleTypeDescription0actionhomestringName of your action1scoreloaded from config0.7floatIt's optionalComplete Example
----------------

[](#complete-example)

##### View:

[](#view)

```

        Recaptcha v3

        {!! Recaptcha::renderJs('fa') !!}

            {!! csrf_field() !!}
            {!! Recaptcha::field('home', 'g-recaptcha-response', ['id' => 'recaptcha-id', 'class' => 'form-element'], 'recaptchaCallback') !!}

            Submit

        @if($errors->any())
            @foreach($errors->all() as $key => $error)
                {{ $key }} - {{ $error }}
            @endforeach
        @endif

            function recaptchaCallback(token) {
                console.log('token retrieved:');
                console.log(token);
            }

```

##### Controller:

[](#controller)

```
class DevController extends Controller
{
    public function verifyRecaptcha(Request $request)
    {
        $this->validate($request, ['g-recaptcha-response' => 'required|recaptcha:home,0.5']);
        dd($request->all());
    }
}
```

Migration Guide
---------------

[](#migration-guide)

##### from 1.0.0 to 1.1.0

[](#from-100-to-110)

- delete `app/recaptcha.php` file
- delete `resources/views/vendor/recaptcha` directory
- publish vendor again ```
    php artisan vendor:publish --provider="Mostafaznv\Recaptcha\RecaptchaServiceProvider"
    ```

Changelog
---------

[](#changelog)

Refer to the [Changelog](CHANGELOG.md) for a full history of the project.

License
-------

[](#license)

This software is released under [The MIT License (MIT)](LICENSE).

(c) 2018 Mostafaznv, All rights reserved.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 78.9% 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 ~181 days

Recently: every ~232 days

Total

9

Last Release

1284d ago

Major Versions

1.1.5 → V2.0.02022-10-04

### Community

Maintainers

![](https://www.gravatar.com/avatar/e0663cc3c9ca4ae9518ca84d8effc62c4aed193f06651095d6b8d4c9b36f816a?d=identicon)[vlinde](/maintainers/vlinde)

---

Top Contributors

[![mostafaznv](https://avatars.githubusercontent.com/u/7619687?v=4)](https://github.com/mostafaznv "mostafaznv (15 commits)")[![marian-vlinde](https://avatars.githubusercontent.com/u/56548392?v=4)](https://github.com/marian-vlinde "marian-vlinde (4 commits)")

---

Tags

laravellaravel 6laravel 7laravel 8laravel 9recaptchalaravel 5Google ReCaptchano-captcharecaptcha v3mostafaznvpackalyst

### Embed Badge

![Health badge](/badges/vlinde-recaptcha/health.svg)

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

###  Alternatives

[mostafaznv/recaptcha

Laravel package for Google Recaptcha v3

2127.5k](/packages/mostafaznv-recaptcha)[anhskohbo/no-captcha

No CAPTCHA reCAPTCHA For Laravel.

1.8k8.5M33](/packages/anhskohbo-no-captcha)[itsmurumba/laravel-mpesa

Laravel Package for Mpesa Daraja API

191.6k](/packages/itsmurumba-laravel-mpesa)

PHPackages © 2026

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