Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

Commit 29812e1

Browse files
committed
Merge branch 'develop' into release/v3
* develop: code comments routes folder removed Update README.md Load routes in ReCaptchaServiceProvider::registerRoutes method Update README.md Update README.md Update README.md
2 parents 06d8ad5 + dd0d39d commit 29812e1

File tree

3 files changed

+37
-149
lines changed

3 files changed

+37
-149
lines changed

README.md

Lines changed: 9 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,138 +1,24 @@
1-
# Laravel ReCAPTCHA - v3
1+
# Laravel ReCAPTCHA v3
22
Simple and painless Google reCAPTCHA package for Laravel 5
33

4-
[![Build Status](https://travis-ci.org/biscolab/laravel-recaptcha.svg?branch=master)](https://travis-ci.org/biscolab/laravel-recaptcha) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/biscolab/laravel-recaptcha/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/biscolab/laravel-recaptcha/?branch=master) ![Packagist version](https://img.shields.io/packagist/v/biscolab/laravel-recaptcha.svg)
4+
Available reCAPTCHA versions:
5+
* v2 Invisible
6+
* v2 Checkbox
7+
* v3
8+
9+
[![Build Status](https://travis-ci.org/biscolab/laravel-recaptcha.svg?branch=master)](https://travis-ci.org/biscolab/laravel-recaptcha) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/biscolab/laravel-recaptcha/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/biscolab/laravel-recaptcha/?branch=master) [![Packagist version](https://img.shields.io/packagist/v/biscolab/laravel-recaptcha.svg#img-thumbnail)](https://packagist.org/packages/biscolab/laravel-recaptcha)
510

611
## System requirements
712
| Package version | PHP version | Laravel version |
813
|-----------------|-------------|-----------------|
914
| 3.x | 7.1 or greater | 5.5 or greater |
15+
| 2.x | 5.5.9, 7.0 or greater | 5.0 or greater |
1016

1117
Are you still using PHP 5.x or 7.0? Please go to [V2](https://github.com/biscolab/laravel-recaptcha/tree/v2.0.4)
1218

1319
## !!! Documentation !!!
1420

15-
Since version 3.2.0 you can find online complete documentation at [https://laravel-recaptcha-docs.biscolab.com/](https://laravel-recaptcha-docs.biscolab.com/).
16-
For previous releases continue reading.
17-
18-
## Installation
19-
20-
You can install the package via composer:
21-
```sh
22-
composer require biscolab/laravel-recaptcha:^3.0
23-
```
24-
Laravel 5.5 (or greater) uses package auto-discovery, so doesn't require you to manually add the Service Provider, but if you don't use auto-discovery `ReCaptchaServiceProvider` must be registered in `config/app.php`:
25-
```php
26-
'providers' => [
27-
...
28-
Biscolab\ReCaptcha\ReCaptchaServiceProvider::class,
29-
];
30-
```
31-
You can use the facade for shorter code. Add `ReCaptcha` to your aliases:
32-
```php
33-
'aliases' => [
34-
...
35-
'ReCaptcha' => Biscolab\ReCaptcha\Facades\ReCaptcha::class,
36-
];
37-
```
38-
Create `config/recaptcha.php` configuration file using:
39-
```su
40-
php artisan vendor:publish --provider="Biscolab\ReCaptcha\ReCaptchaServiceProvider"
41-
```
42-
43-
## Configuration
44-
45-
### Add your API Keys
46-
Open `.env` file and set `RECAPTCHA_SITE_KEY` and `RECAPTCHA_SECRET_KEY`:
47-
```php
48-
RECAPTCHA_SITE_KEY=YOUR_API_SITE_KEY
49-
RECAPTCHA_SECRET_KEY=YOUR_API_SECRET_KEY
50-
```
51-
52-
Open `config/recaptcha.php` configuration file and set `version`:
53-
```php
54-
return [
55-
'api_site_key' => env('RECAPTCHA_SITE_KEY', ''),
56-
'api_secret_key' => env('RECAPTCHA_SECRET_KEY', ''),
57-
'version' => 'v2' // supported: v2|invisible
58-
'skip_ip' => [] // array of IP addresses - String: dotted quad format e.g.: 127.0.0.1
59-
];
60-
```
61-
For more invermation about Site Key and Secret Key please visit [Google reCAPTCHA developer documentation](https://developers.google.com/recaptcha/docs/start)
62-
Get more info about reCAPTCHA version at https://developers.google.com/recaptcha/docs/versions
63-
**skip_ip** is a list of IP addresses that, if recognized, disable the reCAPTCHA validation (return always true).
64-
65-
### Have you updated?
66-
If you are migrating from an older version add `skip_ip` array in `recaptcha.php` configuration file.
67-
68-
### Customize error message
69-
Before starting please add the validation message to `resources/lang/[LANG]/validation.php` file
70-
```php
71-
return [
72-
...
73-
'recaptcha' => 'Hey!!! :attribute is wrong!',
74-
];
75-
```
76-
77-
## How to use
78-
79-
### Embed in Blade
80-
81-
Insert `htmlScriptTagJsApi($formId)` helper before closing `</head>` tag
82-
You can also use `ReCaptcha::htmlScriptTagJsApi($formId)`.
83-
`$formId` is required only if you are using **ReCAPTCHA INVISIBLE**
84-
```blade
85-
<!DOCTYPE html>
86-
<html>
87-
<head>
88-
...
89-
{!! htmlScriptTagJsApi(/* $formId - INVISIBLE version only */) !!}
90-
or
91-
{!! ReCaptcha::htmlScriptTagJsApi(/* $formId - INVISIBLE version only */) !!}
92-
</head>
93-
```
94-
95-
#### If you are using ReCAPTCHA v2
96-
After you have to insert `htmlFormSnippet()` helper inside the form where you want to use the field `g-recaptcha-response`
97-
You can also use `ReCaptcha::htmlFormSnippet()` .
98-
```blade
99-
<form>
100-
...
101-
{!! htmlFormSnippet() !!}
102-
<input type="submit">
103-
</form>
104-
```
105-
106-
#### If you are using ReCAPTCHA INVISIBLE
107-
After you have to insert `htmlFormButton($buttonInnerHTML)` helper inside the form where you want to use ReCAPTCHA. This function creates submit button therefore **you don't have to insert <input type="submit"> or similar**.
108-
You can also use `ReCaptcha::htmlFormButton($buttonInnerHTML)` .
109-
`$buttonInnerHTML` is what you want to write on the submit button
110-
```blade
111-
<form>
112-
...
113-
{!! htmlFormButton(/* $buttonInnerHTML - Optional */) !!}
114-
</form>
115-
```
116-
117-
## Verify submitted data
118-
119-
Add **recaptcha** to your rules
120-
```php
121-
$v = Validator::make(request()->all(), [
122-
...
123-
'g-recaptcha-response' => 'recaptcha',
124-
]);
125-
```
126-
127-
Print form errors
128-
```php
129-
$errors = $v->errors();
130-
```
131-
132-
## Test
21+
You can find online complete documentation at [https://laravel-recaptcha-docs.biscolab.com/](https://laravel-recaptcha-docs.biscolab.com/).
13322

134-
```sh
135-
composer test
136-
```
13723
## License
13824
[![MIT License](https://img.shields.io/github/license/biscolab/laravel-recaptcha.svg)](https://github.com/biscolab/laravel-recaptcha/blob/master/LICENSE)

src/ReCaptchaServiceProvider.php

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace Biscolab\ReCaptcha;
1212

13+
use Illuminate\Support\Facades\Route;
1314
use Illuminate\Support\ServiceProvider;
1415
use Validator;
1516

@@ -32,8 +33,8 @@ class ReCaptchaServiceProvider extends ServiceProvider {
3233
public function boot() {
3334

3435
$this->addValidationRule();
35-
$this->loadRoutesFrom(__DIR__ . '/routes/routes.php');
36-
36+
// $this->loadRoutesFrom(__DIR__ . '/routes/routes.php');
37+
$this->registerRoutes();
3738
$this->publishes([
3839
__DIR__ . '/../config/recaptcha.php' => config_path('recaptcha.php'),
3940
]);
@@ -65,6 +66,31 @@ public function register() {
6566
$this->registerReCaptchaBuilder();
6667
}
6768

69+
/**
70+
* Get the services provided by the provider.
71+
*
72+
* @return array
73+
*/
74+
public function provides(): array {
75+
76+
return ['recaptcha'];
77+
}
78+
79+
/**
80+
* @return ReCaptchaServiceProvider
81+
*
82+
* @since v3.4.1
83+
*/
84+
protected function registerRoutes(): ReCaptchaServiceProvider {
85+
86+
Route::get(
87+
config('recaptcha.default_validation_route', 'biscolab-recaptcha/validate'),
88+
['uses' => 'Biscolab\ReCaptcha\Controllers\ReCaptchaController@validateV3']
89+
)->middleware('web');
90+
91+
return $this;
92+
}
93+
6894
/**
6995
* Register the HTML builder instance.
7096
*
@@ -93,14 +119,4 @@ protected function registerReCaptchaBuilder() {
93119
});
94120
}
95121

96-
/**
97-
* Get the services provided by the provider.
98-
*
99-
* @return array
100-
*/
101-
public function provides() {
102-
103-
return ['recaptcha'];
104-
}
105-
106122
}

src/routes/routes.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)