Package Data | |
---|---|
Maintainer Username: | astritzeqiri |
Maintainer Contact: | astritzeqiri5@gmail.com (Astrit Zeqiri) |
Package Create Date: | 2016-08-26 |
Package Last Update: | 2021-06-07 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-10-26 15:03:54 |
Package Statistics | |
---|---|
Total Downloads: | 54 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Easily add google recaptcha
Add astritzeqiri/g-recaptcha to your composer.json file:
"require": {
"astritzeqiri/g-recaptcha": "~1.0"
}
And do:
$ composer update
Or get composer to install the package:
$ composer require astritzeqiri/g-recaptcha
Now you go and generate a new Google recaptcha on the link below:
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.
return [
'enabled' => env("GRECAPTCHA_ENABLED", true),
'site_key' => env("GRECAPTCHA_KEY"),
'secret_key' => env("GRECAPTCHA_SECRET"),
];
Register the service provider within the providers
array found in app/config/app.php
:
'providers' => array(
// ...
AstritZeqiri\GRecaptcha\GRecaptchaServiceProvider::class
)
Then you need to add GRecaptcha class within the aliases
array found in app/config/app.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
First 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.
// in blade.php files
{!! \GRecaptcha::renderScripts() !!}
// or in .php files
<?php echo GRecaptcha::renderScripts(); ?>
Now to render a new GRecaptcha you call the render method.
// 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:
$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();
When you validate a form to validate the recaptcha you use the rule grecaptcha
$validator = Validator::make($inputs,
['g-recaptcha-response' => 'required|grecaptcha']
);