laravel-grecaptcha
This package allows an easily management of Google Recaptcha on your Laravel projects., (*1)
Prerequisites
Google Recaptcha V2 site key and secret key available on ReCAPTCHA website, (*2)
Installation
composer require "mmilidoni/grecaptcha:dev-master", (*3)
Configuration
Add your Recaptcha site key and secret key on config/services.php, (*4)
"grecaptcha" => [
"secret" => "*****",
"sitekey" => "****",
],
View
Insert the following line on your HTML header, (*5)
<script src='https://www.google.com/recaptcha/api.js'></script>
Insert the following line on your HTML form, (*6)
<div class="g-recaptcha" data-sitekey="{{ config("services.grecaptcha.sitekey") }}"></div>
Controller
use Mmilidoni\Grecaptcha\Grecaptcha;
class Example {
public function store(\Illuminate\Http\Request $request) {
$a = new Grecaptcha;
if ($a->check($request)) {
// Recaptcha OK
} else {
// Recaptcha KO
}
}
}