Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kutia-software-company/laravel-google-recaptcha
Laravel 5 Easily add google recaptcha.
https://github.com/kutia-software-company/laravel-google-recaptcha
captcha google-recaptcha grecaptcha laravel laravel-captcha php
Last synced: about 1 month ago
JSON representation
Laravel 5 Easily add google recaptcha.
- Host: GitHub
- URL: https://github.com/kutia-software-company/laravel-google-recaptcha
- Owner: kutia-software-company
- License: mit
- Created: 2016-08-26T12:32:08.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-06-07T13:36:24.000Z (over 3 years ago)
- Last Synced: 2024-04-16T06:27:09.523Z (8 months ago)
- Topics: captcha, google-recaptcha, grecaptcha, laravel, laravel-captcha, php
- Language: PHP
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![StyleCI](https://styleci.io/repos/66646162/shield)](https://styleci.io/repos/66646162/)
[![Total Downloads](https://poser.pugx.org/astritzeqiri/g-recaptcha/downloads)](https://packagist.org/packages/astritzeqiri/g-recaptcha)# Google recaptcha for Laravel
Easily add google recaptcha in Laravel.
## Requirements
- PHP >=5.4
- Laravel >= 5.0
- GuzzleHttp >= 5.3## Installation
Add astritzeqiri/g-recaptcha to your composer.json file:
```json
"require": {
"astritzeqiri/g-recaptcha": "~1.0"
}
```And do:
```
$ composer update
```Or get composer to install the package:
```
$ composer require astritzeqiri/g-recaptcha
```## Configuration
Now you go and generate a new Google recaptcha on the link below:
[Google Recaptcha Generate](https://www.google.com/recaptcha/intro/index.html ).
Then you go to your .env file and set these variables
```
# If you want to disable captchas put this to false by default this is true.
GRECAPTCHA_ENABLED=true# The google recaptcha site key
GRECAPTCHA_KEY=SITE_KEY# The google recaptcha secret key
GRECAPTCHA_SECRET=SECRET_KEY
```You can also change these variables on the config file on config/grecaptcha.php file.
```php
return [
'enabled' => env("GRECAPTCHA_ENABLED", true),
'site_key' => env("GRECAPTCHA_KEY"),
'secret_key' => env("GRECAPTCHA_SECRET"),
];
```### Registering the Package
Register the service provider within the `providers` array found in `app/config/app.php`:
```php
'providers' => array(
// ...
AstritZeqiri\GRecaptcha\GRecaptchaServiceProvider::class
)
```Then you need to add GRecaptcha class within the `aliases` array found in `app/config/app.php`:
```php
'aliases' => array(
// ...
'GRecaptcha' => AstritZeqiri\GRecaptcha\GRecaptcha::class,
)
```Then you run php artisan vendor:publish to publish the start_captchas script and also the recaptcha config file.
```
$ php artisan vendor:publish
```
## UsageFirst of all you need to call the grecaptcha scripts on the footer. The scripts are rendered only if you have an active captcha somewhere on you html.
```php
// in blade.php files
{!! \GRecaptcha::renderScripts() !!}// or in .php files
```
### Basic Example
Now to render a new GRecaptcha you call the render method.
```php
// by default it echo's it out
GRecaptcha::render();// if you want to save the html in a variable you call
$grecaptchaHtml = GRecaptcha::render([], false);
```If you want to get a new recaptcha instance:
```php
$grecaptcha = GRecaptcha::generate();// to render it you call
$grecaptcha->renderHtml();// if you dont want it to be rendered but store the html you call
$grecaptchaHtml = $grecaptcha->build();
```### Validation
When you validate a form to validate the recaptcha you use the rule grecaptcha
```php
$validator = Validator::make($inputs,
['g-recaptcha-response' => 'required|grecaptcha']
);
```## License
[MIT](/LICENSE)