adiachenko / laravel-recaptcha
Google reCAPTCHA for Laravel framework
Installs: 270
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 1
Forks: 0
Open Issues: 0
Language:HTML
Requires
- php: >=5.5.9
- guzzlehttp/guzzle: ^6.0
- illuminate/support: ^5.1
This package is auto-updated.
Last update: 2019-01-25 18:28:52 UTC
README
reCAPTCHA is a free service that protects your site from spam and abuse. It uses advanced risk analysis techniques to tell humans and bots apart.
How is this package any different?
- hands-off approach in regards to your front-end. No obscure render helpers, only prepared ready to use templates that you can customize to your liking or throw away if you deem so.
- its functionality can be globally disabled by commenting out corresponding credentials in your
.env
file. Therefore it doesn't intervene with either browser testing facilities or your development workflow in general
Both v2 and Invisible reCAPTCHA are supported.
Installation
To get started, install LaravelRecaptcha via the Composer package manager:
composer require adiachenko/laravel-recaptcha
Register the LaravelRecaptcha service provider in the providers
array of your config/app.php
configuration file
Adiachenko\LaravelRecaptcha\RecaptchaServiceProvider::class,
Configure your reCAPTCHA credentials in config/services.php
file:
'recaptcha' => [
'key' => env('RECAPTCHA_SITE_KEY'),
'secret' => env('RECAPTCHA_SECRET_KEY'),
],
Next, add them to your .env
file. Follow this link to create your own credentials.
If any of the credentials are null or not set, reCAPTCHA will be globally disabled even with all other boilerplate in place. Yay!
RECAPTCHA_SITE_KEY=
RECAPTCHA_SECRET_KEY=
Add the following validation rule to your would-be reCAPTCHA protected form:
'g-recaptcha-response' => 'recaptcha',
It's recommended to omit required validation rule, because you probably only want to protect your form in production and skip development(testing) environments.
To publish the pre-build view partials, use the vendor:publish
Artisan command. The default markup assumes Bootstrap 4, but it's easy to customize:
php artisan vendor:publish --tag=laravel-recaptcha
Lastly, add the named stack @stack('scripts')
to your layout if you haven't already (anywhere will do, but make sure it renders before your protected form) and include the partial in your form of choice:
The script tag is not defined withing the form itself so that you don't accidentally encounter issues when using JavaScript framework (in fact, this is the case for Vue.js).
reCAPTCHA v2:
@include('vendor.recaptcha.v2')
Invisible reCAPTCHA:
@include('vendor.recaptcha.invisible', [
'selector' => '#forgot-password',
'text' => 'Send Password Reset Link',
'class' => 'btn btn-outline-primary'
])
Invisible reCAPTCHA hooks into your form submit button dynamically rather then printing a separate widget, hence we need to provide some additional data to render an actual button. selector
in this case is the query selector for your protected form.