Google reCaptcha Enterprise Package for Laravel

Packages

February 2nd, 2023

Google reCaptcha Enterprise Package for Laravel

The Google reCaptcha Enterprise for Laravel is a package that provides easy configuration of reCaptcha and a handy validation rule to verify your user token scores.

Here's an example of how you can use this package to validate the user's Recaptcha score using the provided validation Rule class:

use Illuminate\Foundation\Http\FormRequest;
use Oneduo\RecaptchaEnterprise\Rules\Recaptcha;
 
class TestRequest extends FormRequest
{
public function rules(): array
{
return [
'g-recaptcha-response' => [
'required',
new Recaptcha()
],
];
}
 
public function authorize(): bool
{
return true;
}
}

When validating a reCaptcha token, you need to configure a score threshold acceptable for considering the user as valid. You can customize your app's score based on reCaptcha data using the provided configuration option in this package:

// config/recaptcha-enterprise.php
return [
'score_threshold' => 0.7,
// ...
];

You can get started with this package on GitHub at oneduo/laravel-recaptcha-enterprise and install it via composer:

composer require oneduo/laravel-recaptcha-enterprise

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.