PHPackages                             dutchcodingcompany/no-captcha - 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. dutchcodingcompany/no-captcha

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

dutchcodingcompany/no-captcha
=============================

No CAPTCHA reCAPTCHA For Laravel.

3.1.0(4y ago)018MITPHPPHP &gt;=5.5.5

Since Dec 4Pushed 4y agoCompare

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

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

No CAPTCHA reCAPTCHA
====================

[](#no-captcha-recaptcha)

[![Build Status](https://camo.githubusercontent.com/65a912c020c2ea07de625acf62067b6172c0faa0113f48a15db298281d6bf33e/68747470733a2f2f7472617669732d63692e6f72672f6475746368636f64696e67636f6d70616e792f6e6f2d636170746368612e7376673f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://travis-ci.org/dutchcodingcompany/no-captcha)[![Latest Stable Version](https://camo.githubusercontent.com/b3e61aea6dfc61cb33037cf091242d428d02b10f26cafe24ec2fc32f03e10a6c/68747470733a2f2f706f7365722e707567782e6f72672f6475746368636f64696e67636f6d70616e792f6e6f2d636170746368612f762f737461626c65)](https://packagist.org/packages/dutchcodingcompany/no-captcha)[![Total Downloads](https://camo.githubusercontent.com/b931fe4992f1b4cc68b9f4fba444be1068a3670291a8a5325bddffa5dbd4ed2d/68747470733a2f2f706f7365722e707567782e6f72672f6475746368636f64696e67636f6d70616e792f6e6f2d636170746368612f646f776e6c6f616473)](https://packagist.org/packages/dutchcodingcompany/no-captcha)[![Latest Unstable Version](https://camo.githubusercontent.com/393b3aac6adeddb1b8cd6a72c7305338bec0c57c94d434f2f64696d23ec80136/68747470733a2f2f706f7365722e707567782e6f72672f6475746368636f64696e67636f6d70616e792f6e6f2d636170746368612f762f756e737461626c65)](https://packagist.org/packages/dutchcodingcompany/no-captcha)[![License](https://camo.githubusercontent.com/93c3b477ece49b2440719b8942b7913fb821c01a708b30b74775c1a68d8fa577/68747470733a2f2f706f7365722e707567782e6f72672f6475746368636f64696e67636f6d70616e792f6e6f2d636170746368612f6c6963656e7365)](https://packagist.org/packages/dutchcodingcompany/no-captcha)

[![recaptcha_anchor 2x](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)

> This is a fork of [anhskohbo/no-captcha](https://github.com/anhskohbo/no-captcha) which seems no longer supported!

> For Laravel 4 use [v1](https://github.com/DutchCodingCompany/no-captcha/tree/v1) branch.

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

[](#installation)

```
composer require DutchCodingCompany/no-captcha

```

Laravel 5 and above
-------------------

[](#laravel-5-and-above)

### Setup

[](#setup)

***NOTE*** This package supports the auto-discovery feature of Laravel 5.5 and above, So skip these `Setup` instructions if you're using Laravel 5.5 and above.

In `app/config/app.php` add the following :

1- The ServiceProvider to the providers array :

```
DutchCodingCompany\NoCaptcha\NoCaptchaServiceProvider::class,
```

2- The class alias to the aliases array :

```
'NoCaptcha' => DutchCodingCompany\NoCaptcha\Facades\NoCaptcha::class,
```

3- Publish the config file

```
php artisan vendor:publish --provider="DutchCodingCompany\NoCaptcha\NoCaptchaServiceProvider"

```

### Configuration

[](#configuration)

Add `NOCAPTCHA_SECRET` and `NOCAPTCHA_SITEKEY` in **.env** file :

```
NOCAPTCHA_SECRET=secret-key
NOCAPTCHA_SITEKEY=site-key

```

(You can obtain them from [here](https://www.google.com/recaptcha/admin))

### Usage

[](#usage)

#### Init js source

[](#init-js-source)

With default options :

```
 {!! NoCaptcha::renderJs() !!}
```

With [language support](https://developers.google.com/recaptcha/docs/language) or [onloadCallback](https://developers.google.com/recaptcha/docs/display#explicit_render) option :

```
 {!! NoCaptcha::renderJs('fr', true, 'recaptchaCallback') !!}
```

#### Display reCAPTCHA

[](#display-recaptcha)

Default widget :

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

With [custom attributes](https://developers.google.com/recaptcha/docs/display#render_param) (theme, size, callback ...) :

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

Invisible reCAPTCHA using a [submit button](https://developers.google.com/recaptcha/docs/invisible):

```
{!! NoCaptcha::displaySubmit('my-form-id', 'submit now!', ['data-theme' => 'dark']) !!}
```

Notice that the id of the form is required in this method to let the autogenerated callback submit the form on a successful captcha verification.

#### Validation

[](#validation)

Add `'g-recaptcha-response' => 'required|captcha'` to rules array :

```
$validate = Validator::make(Input::all(), [
	'g-recaptcha-response' => 'required|captcha'
]);
```

##### 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.',
        'captcha' => '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
```

### Testing

[](#testing)

When using the [Laravel Testing functionality](http://laravel.com/docs/5.5/testing), you will need to mock out the response for the captcha form element.

So for any form tests involving the captcha, you can do this by mocking the facade behavior:

```
// prevent validation error on captcha
NoCaptcha::shouldReceive('verifyResponse')
    ->once()
    ->andReturn(true);

// provide hidden input for your 'required' validation
NoCaptcha::shouldReceive('display')
    ->zeroOrMoreTimes()
    ->andReturn('');
```

You can then test the remainder of your form as normal.

When using HTTP tests you can add the `g-recaptcha-response` to the request body for the 'required' validation:

```
// prevent validation error on captcha
NoCaptcha::shouldReceive('verifyResponse')
    ->once()
    ->andReturn(true);

// POST request, with request body including g-recaptcha-response
$response = $this->json('POST', '/register', [
    'g-recaptcha-response' => '1',
    'name' => 'John',
    'email' => 'john@example.com',
    'password' => '123456',
    'password_confirmation' => '123456',
]);
```

Without Laravel
---------------

[](#without-laravel)

Checkout example below:

```
