Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

LaraBug/larabug-app

218 stars
3 code files
View LaraBug/larabug-app on GitHub

composer.json

Open in GitHub
{
//
"require": {
"php": "^8.0",
//
"google/recaptcha": "~1.1"
},
//
}

app/Traits/Captcha.php

Open in GitHub
use 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 GitHub
class 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();
}
//
}
//
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.