-
composer.json
Open in GitHub{ // "require": { "php": "^8.0", // "google/recaptcha": "~1.1" }, // }
-
app/Traits/Captcha.php
Open in GitHubuse ReCaptcha\ReCaptcha; use Illuminate\Http\Request; trait Captcha { public function captchaCheck(Request $request) { $response = $request->input('g-recaptcha-response'); $remoteip = $request->ip(); $secret = env('RE_CAP_SECRET'); $recaptcha = new ReCaptcha($secret); $resp = $recaptcha->verify($response, $remoteip); if ($resp->isSuccess()) { return true; } else { return false; } } }
-
app/Http/Controllers/Auth/RegisterController.php
Open in GitHubclass RegisterController extends Controller { // public function register(Request $request) { $this->validator($request->all())->validate(); if ($this->captchaCheck($request) == false) { return redirect()->back() ->withErrors(['captcha' => 'You did not validate the captcha correctly.']) ->withInput(); } // } // }