origami / captcha
Simple Google Captcha integration for Laravel projects
Installs: 6 355
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^7.2|^8.0.2
- google/recaptcha: ^1.2
- illuminate/support: ^6.0|^7.0|^8.0|^9.0|^10.0
- illuminate/validation: ^6.0|^7.0|^8.0|^9.0|^10.0
README
This package adds a validation rule and controller trait for easier integration with Google Recaptcha
Installation
Install this package through Composer.
composer require origami/captcha
Requirements
This package is designed to work with Laravel >= 6 currently. If you require 5.8 support, use version 1.
Setup
-
Signup for a Google Recaptcha account at https://www.google.com/recaptcha/admin
-
You should add a recatpcha section to your
config/services.php
file:
'recaptcha' => [ 'key' => env('RECAPTCHA_KEY'), 'secret' => env('RECAPTCHA_SECRET'), ],
- Update your
.env
file with the key and secret:
RECAPTCHA_KEY=
RECAPTCHA_SECRET=
- Add a language line to your validation file(s), e.g.
resources/lang/en/validation.php
'recaptcha' => 'The reCAPTCHA check was invalid',
Usage
Validator
$validator = Validator::make($request->all(), [ 'recaptcha' => 'recaptcha', ]);
Controller Validation
(Assuming your Controller has the ValidatesRequests
trait)
class Contact extends Controller { public function store(Request $request) { $this->validate($request, [ 'recatpcha' => 'recaptcha' ]); } }
Controller with ValidatesCaptcha Trait
use Origami\Captcha\ValidatesCaptcha; class Contact extends Controller { use ValidatesCaptcha; public function store(Request $request) { $this->validateCatpcha($request); // The above will throw a ValidationException when the recaptcha fails. } }
Blade Helpers
This packages registers two Blade helpers:
@recaptchaField
is the equivalent of:
<div class="g-recaptcha" data-sitekey="{{ config('services.recaptcha.key') }}"></div>
@recaptchaScript
is the equivalent of:
<script src="https://www.google.com/recaptcha/api.js"></script>