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

ActiveLibrary

gopalindians/no-captcha
=======================

No CAPTCHA reCAPTCHA For Laravel.

02↓100%PHP

Since Mar 18Pushed 1mo agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

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

[](#no-captcha-recaptcha)

[![Build Status](https://camo.githubusercontent.com/515c6c791c3ebb276ed8986d610f444f31eb66190b5ec3c990e0cbf89db0262e/68747470733a2f2f7472617669732d63692e6f72672f616e68736b6f68626f2f6e6f2d636170746368612e7376673f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://travis-ci.org/anhskohbo/no-captcha)[![Latest Stable Version](https://camo.githubusercontent.com/14715490c5b796ef7f30ae9f277ea53d26be0ab9d63cd2256b24c6673ba0ef81/68747470733a2f2f706f7365722e707567782e6f72672f616e68736b6f68626f2f6e6f2d636170746368612f762f737461626c65)](https://packagist.org/packages/anhskohbo/no-captcha)[![Total Downloads](https://camo.githubusercontent.com/fd48aa77d927c9addc9d04ae5df379aea37d82ca168d6a46f51900010508a6b3/68747470733a2f2f706f7365722e707567782e6f72672f616e68736b6f68626f2f6e6f2d636170746368612f646f776e6c6f616473)](https://packagist.org/packages/anhskohbo/no-captcha)[![Latest Unstable Version](https://camo.githubusercontent.com/135684e126c8e405e0f53d160102ec4fd3388f7d84aa9711b5781cc62a83dcf8/68747470733a2f2f706f7365722e707567782e6f72672f616e68736b6f68626f2f6e6f2d636170746368612f762f756e737461626c65)](https://packagist.org/packages/anhskohbo/no-captcha)[![License](https://camo.githubusercontent.com/5fca732b318ce132564a84836b1157bb9942530b16bca93512df7425a6aea937/68747470733a2f2f706f7365722e707567782e6f72672f616e68736b6f68626f2f6e6f2d636170746368612f6c6963656e7365)](https://packagist.org/packages/anhskohbo/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)

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

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

[](#installation)

```
composer require anhskohbo/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 :

```
Anhskohbo\NoCaptcha\NoCaptchaServiceProvider::class,
```

2- The class alias to the aliases array :

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

3- Publish the config file

```
php artisan vendor:publish --provider="Anhskohbo\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:

```
