turkmentv/app/Rules/ReCaptchaRule.php

47 lines
965 B
PHP
Raw Normal View History

2020-11-24 06:59:59 +00:00
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
use ReCaptcha\ReCaptcha;
class ReCaptchaRule implements Rule
{
public function __construct()
{}
public function passes($attribute, $value)
{
// if (empty($value)) {
// $this->error_msg = ':attribute field is required.';
// return false;
// }
$recaptcha = new ReCaptcha('6LelUOQZAAAAAHBAEnflw1XLOvCgaAeKQb4TilEb');
$resp = $recaptcha->verify($value, $_SERVER['REMOTE_ADDR']);
//dd($resp);
// if (!$resp->isSuccess()) {
// $this->error_msg = 'ReCaptcha field is required.';
// return false;
// }
// if ($resp->getScore() < 0.5) {
// $this->error_msg = 'Failed to validate captcha.';
// return false;
// }
return $resp;
}
public function message()
{
return "smth went wrong";
}
}