google/recaptcha
PHP client library for Google reCAPTCHA v2 and v3. Provides server-side verification of reCAPTCHA responses with simple APIs, Composer install, and PSR-4 autoloading to help protect sites from spam and abuse.
Pros:
readonly classes (PR #617, #618) improve type safety and maintainability, reducing runtime errors in Laravel’s strict typing environment.challenge_ts, SocketPost failures, and case-insensitive hostname matching (PR #608, #610, #622) address subtle but critical failure modes in production (e.g., proxy environments, malformed responses).Cons:
App\Providers\RecaptchaServiceProvider or custom wrappers.readonly classes and promoted constructors (PR #618) could break serialization/deserialization in custom integrations (e.g., caching reCAPTCHA responses).SocketPost (PR #598) might affect apps overriding default HTTP methods.stream_get_contents (PR #611) improves memory usage but could introduce edge cases in high-load scenarios (e.g., concurrent requests).validateRecaptcha rule, but custom validators using internal package methods may need updates.SocketPost (PR #616) could affect middleware relying on raw HTTP responses (e.g., custom reCAPTCHA logging).challenge_ts, error codes) should guide Laravel test suites to validate robustness.Mockery or PHPUnit test doubles.null in reCAPTCHA responses (e.g., cached data) may fail. Example:
// Old (may break):
$response = Recaptcha::verify($token);
if ($response->success === null) { ... }
// New (strict null checks):
$response->success; // Throws if null
readonly properties.SocketPost, DTO properties) that may break?null values in reCAPTCHA responses for legacy code?challenge_ts, proxy responses)?$this->app->singleton(Recaptcha::class, function ($app) {
return new \Recaptcha\Recaptcha(
siteKey: config('services.recaptcha.site_key'),
secret: config('services.recaptcha.secret'),
version: config('services.recaptcha.version')
);
});
// Old (may break):
$response = Recaptcha::verify($token);
if (!$response->success) { ... }
// New (recommended):
if (!$response->isSuccess()) { ... } // If method exists
public function handle(Request $request, Closure $next) {
try {
$response = Recaptcha::verify($request->recaptcha_token);
if (!$response->isSuccess()) {
return redirect()->back()->withErrors(['recaptcha' => 'Invalid token']);
}
} catch (RecaptchaException $e) {
// Log timeout/SSL errors
logger()->error('reCAPTCHA failure', ['error' => $e->getMessage()]);
}
return $next($request);
}
e() helper).SocketPost or HTTP methods.composer.json to require PHP 8.4+ if needed.challenge_ts, proxy responses).retry helper).readonly classes and strict types, but not recommended long-term.openssl and curl are enabled for TLS improvements..env and config/services.php.composer update google/recaptcha.How can I help you explore Laravel packages today?