Downloads
Stars
Version
A reCAPTCHA library with out of the box Laravel integration. This is merely a wrap for romainneutron/ReCaptcha, as to add Laravel integration, therefore, all methods present in the Neutron/ReCaptcha\ReCaptcha
class are also available here.
The best way to install the package is through Composer.
composer.json
"require": {
"rmobis/recaptcha-laravel": "0.1.*"
}
app/config/app.php
// Providers
'Rmobis\Recaptcha\RecaptchaServiceProvider'
...
// Aliases
'Recaptcha' => 'Rmobis\Recaptcha\Facade',
This is where you'll set up your public and private keys, as well as your customization options. To export the configuration file, do:
php artisan config:publish rmobis/recaptcha-laravel
This allows you to use the Recaptcha class in the same way you use all Laravel classes, keeping your code shining and awesome. For instance, if you were to manually check if a given request was correctly made, this is how you'd do it.
$challenge = Input::get('recaptcha_challenge_field');
$response = Input::get('recaptcha_response_field');
if (Recaptcha::check($challenge, $response)) {
// reCAPTCHA verified
} else {
// reCAPTCHA failed
}
This gives you a new validation rule, just like the other ones, which allows you to easily validate all your forms with reCAPTCHA. Simply add it to your validation rules array, and it'll do the magic.
$validator = Validator::make(array(
'recaptcha_response_field' => Input::all(),
// ...
), array(
'recaptcha_response_field' => 'recaptcha',
// ...
));
if ($validator->passes()) {
// reCAPTCHA verified
} else {
// reCAPTCHA failed
}
Gives you an easy way to quickly output all the code needed to output the reCAPTCHA widget. Optionally, you can pass an $options
array, to override and extend the default options, set in the configuration file.
Form::recaptcha(array('theme' => 'clean'))
Generates:
<script type="text/javascript">
var RecaptchaOptions = {"theme":"clean"};
</script>
<script type="text/javascript" src="//www.google.com/recaptcha/api/challenge?k=publicKeyHere"></script>
<noscript>
<iframe src="//www.google.com/recaptcha/api/noscript?k=publicKeyHere" height="300" width="500" frameborder="0"></iframe><br>
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type="hidden" name="recaptcha_response_field" value="manual_challenge">
</noscript>