Add the new required package in your composer.json
"joukhar/laravel-no-captcha-v3": "^1.0"
Run composer update
or php composer.phar update
.
Or install directly via composer
composer require joukhar/laravel-no-captcha-v3
Require php >= 7.4
You can override the default options for The Package. First publish the configuration:
php artisan vendor:publish --provider="Joukhar\LaravelNoCaptchaV3\LaravelNoCaptchaV3" --tag=laravel-no-captcha-v3-config
then Add The following keys to .env file to turn on/off the recaptcha ex:
ENABLE_NO_CAPTCHA=on
GOOGLE_RECAPTCHA_SITE_KEY=
GOOGLE_RECAPTCHA_SECRET_KEY=
And Add your Recaptcha Credentials in the config file:
'recaptcha' => [
'site_key' => env('GOOGLE_RECAPTCHA_SITE_KEY'),
'secret_key' => env('GOOGLE_RECAPTCHA_SECRET_KEY')
]
you can get them here https://www.google.com/u/1/recaptcha/admin/create
If You want to override the default views, you can publish them via:
php artisan vendor:publish --provider="Joukhar\LaravelNoCaptchaV3\LaravelNoCaptchaV3" --tag=laravel-no-captcha-v3-views
Route::post('submit-form', [TestController::class, 'handleFormSubmission']);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<form action="{{ route('validate-form') }}" method="post">
@csrf
@include('NoCaptchaV3::recaptcha-input')
<button type="submit">Submit Form</button>
</form>
{{-- -------------------------------------------------------------------- --}}
{{-- Your Scripts --}}
{{-- -------------------------------------------------------------------- --}}
@include('NoCaptchaV3::recaptcha-script')
</body>
</html>
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Joukhar\LaravelNoCaptchaV3\Http\Controllers\NoCaptchaV3Controller;
class TestController extends Controller
{
public function handleFormSubmission(Request $request, NoCaptchaV3Controller $noCaptchaV3Controller)
{
$request->validate([
'recaptcha' => 'required'
]);
// if reCaptcha Validation has Failed, it will return 'Google reCaptcha Validation has Failed';
// if reCaptcha score >= 0.5, it will return 'safe' otherwise it will return 'not safe' ;
// if ENABLE_NO_CAPTCHA = off , it will return 'false' ;
$recaptchaResult = $noCaptchaV3Controller->reCaptchaResponse();
// conclusion
if ($recaptchaResult == 'safe') {
// your code
}
}
}
The MIT License (MIT). Please see License File for more information.