bghanem/recaptcha-bundle provides a Laravel wrapper for reCAPTCHA (v2/v3) integration, addressing spam prevention, bot mitigation, and form validation. It fits well in architectures requiring:
recaptcha rule) and event hooks (e.g., RecaptchaVerified, RecaptchaFailed), enabling integration with workflows like:
config/recaptcha.php), allowing:
recaptcha.site_key).$request->validate([
'g-recaptcha-response' => 'required|recaptcha',
]);
use Bghanem\RecaptchaBundle\Services\RecaptchaService;
$service = app(RecaptchaService::class);
$result = $service->verify($responseToken);
| Risk Area | Assessment | Mitigation |
|---|---|---|
| Dependency Health | Package has 0 stars/dependents, indicating low adoption. No recent commits (as of 2023). | Evaluate alternative packages (e.g., spatie/laravel-recaptcha) or fork/maintain this bundle. |
| reCAPTCHA API Changes | Google may deprecate endpoints or change response formats. Bundle lacks explicit version pinning for reCAPTCHA API. | Pin google/recaptcha SDK version in composer.json and monitor Google’s deprecation policy. |
| Configuration Rigidity | Hardcoded paths (e.g., config/recaptcha.php) may conflict with custom Laravel structures. |
Override bundle config via config/recaptcha.php or use Laravel’s mergeConfigFrom. |
| Error Handling | Limited documentation on custom error responses (e.g., redirecting users on CAPTCHA failure). | Extend RecaptchaService or create middleware to handle failures uniformly (e.g., flash messages, retries). |
| Testing Coverage | No visible tests in the repo. | Write unit tests for RecaptchaService and integration tests for form/API validation. |
| Performance | reCAPTCHA API calls are synchronous. High traffic may cause latency. | Implement caching (e.g., Redis) for reCAPTCHA responses or use async queues (e.g., Laravel Queues) for non-critical validations. |
Why This Bundle Over Alternatives?
spatie/laravel-recaptcha (more stars, active maintenance) or bestmomo/laravel-recaptcha.reCAPTCHA Version Strategy
API vs. Frontend Usage
Compliance & Privacy
Maintenance Plan
package:discover conflicts.HttpClient instead.symfony/options-resolver and symfony/translation. No conflicts expected in modern Laravel.composer require bghanem/recaptcha-bundle
Publish config:
php artisan vendor:publish --tag=recaptcha-config
config/recaptcha.php with your Google API keys (v2/v3):
return [
'site_key' => env('RECAPTCHA_SITE_KEY'),
'secret_key' => env('RECAPTCHA_SECRET_KEY'),
'version' => 'v3', // or 'v2'
'score_threshold' => 0.5, // for v3
];
recaptcha rule to Form Requests or controllers.
$request->validate(['g-recaptcha-response' => 'required|recaptcha']);
use Bghanem\RecaptchaBundle\Services\RecaptchaService;
$service = app(RecaptchaService::class);
if (!$service->verify($request->input('token'))) {
return response()->json(['error' => 'Invalid CAPTCHA'], 400);
}
Route::middleware(['recaptcha.verify'])->group(function () {
// Routes requiring CAPTCHA
});
Note: Middleware may need customization for API use cases.throttle middleware if needed.RecaptchaService to test validation logic.score_threshold (v3) based on false-positive/negative rates.How can I help you explore Laravel packages today?