ReCaptcha.php 612 B

12345678910111213141516171819202122
  1. <?php
  2. namespace App\Validators;
  3. use GuzzleHttp\Client;
  4. class ReCaptcha
  5. {
  6. public function validate($attribute, $value, $parameters, $validator)
  7. {
  8. $client = new Client;
  9. $response = $client->post(
  10. 'https://www.google.com/recaptcha/api/siteverify',
  11. [
  12. 'form_params' =>
  13. [
  14. 'secret' => config('services.recaptcha.secret'),
  15. 'response' => $value
  16. ]
  17. ]
  18. );
  19. $body = json_decode((string)$response->getBody());
  20. return $body->success;
  21. }
  22. }