|
1 |
| -# Laravel ReCAPTCHA - v3 |
| 1 | +# Laravel ReCAPTCHA v3 |
2 | 2 | Simple and painless Google reCAPTCHA package for Laravel 5
|
3 | 3 |
|
4 |
| -[](https://travis-ci.org/biscolab/laravel-recaptcha) [](https://scrutinizer-ci.com/g/biscolab/laravel-recaptcha/?branch=master)  |
| 4 | +Available reCAPTCHA versions: |
| 5 | +* v2 Invisible |
| 6 | +* v2 Checkbox |
| 7 | +* v3 |
| 8 | + |
| 9 | +[](https://travis-ci.org/biscolab/laravel-recaptcha) [](https://scrutinizer-ci.com/g/biscolab/laravel-recaptcha/?branch=master) [](https://packagist.org/packages/biscolab/laravel-recaptcha) |
5 | 10 |
|
6 | 11 | ## System requirements
|
7 | 12 | | Package version | PHP version | Laravel version |
|
8 | 13 | |-----------------|-------------|-----------------|
|
9 | 14 | | 3.x | 7.1 or greater | 5.5 or greater |
|
| 15 | +| 2.x | 5.5.9, 7.0 or greater | 5.0 or greater | |
10 | 16 |
|
11 | 17 | Are you still using PHP 5.x or 7.0? Please go to [V2](https://github.com/biscolab/laravel-recaptcha/tree/v2.0.4)
|
12 | 18 |
|
13 | 19 | ## !!! Documentation !!!
|
14 | 20 |
|
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/). |
133 | 22 |
|
134 |
| -```sh |
135 |
| -composer test |
136 |
| -``` |
137 | 23 | ## License
|
138 | 24 | [](https://github.com/biscolab/laravel-recaptcha/blob/master/LICENSE)
|
0 commit comments