Files
Credit-Zombies/app/Rules/ReCaptcha.php
2026-06-24 18:29:01 +06:00

55 lines
1021 B
PHP

<?php
namespace App\Rules;
use App\Utility\Curl;
use Illuminate\Contracts\Validation\Rule;
class ReCaptcha implements Rule
{
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
// google captcha url
$url = "https://www.google.com/recaptcha/api/siteverify";
// captcha secret key and value from the UI
$data = [
'secret' => config('app.GOOGLE_RECAPTCHA_SECRET'),
'response' => $value
];
$response = (new Curl($url))->get($data);
return $response['success'];
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return 'The validation error message.';
}
}