JFIF  x x C         C     "        } !1AQa "q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz        w !1AQ aq"2B #3Rbr{ gilour

File "Captcha.php"

Full Path: /var/www/laravel_filter/app/Rules/Captcha.php
File size: 749 bytes
MIME-type: text/x-php
Charset: utf-8

<?php

namespace App\Rules;

use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use App\Models\GoogleRecaptcha;
use ReCaptcha\ReCaptcha;

class Captcha implements ValidationRule
{
    /**
     * Run the validation rule.
     *
     * @param  \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString  $fail
     */
    public function validate(string $attribute, mixed $value, Closure $fail): void
    {
        $google_recaptcha = GoogleRecaptcha::first();
        $recaptcha=new ReCaptcha($google_recaptcha->secret_key);
        $response = $recaptcha->verify($value, $_SERVER['REMOTE_ADDR']);
        if(!$response->isSuccess()){
            $fail('Please complete the recaptcha to submit the form');
        }

    }
}