Here, I will show you how to work laravel 9 google recaptcha v3. I would like to show you laravel 9 google recaptcha example. you'll learn how to use google recaptcha v3 in laravel 9. you'll learn recaptcha v3 in laravel 9. Let's see below example google recaptcha register laravel 9.
Google ReCaptcha V3 is a captcha like system, that provide security against hackers and sticks or curl requests. It assures that a computer user is a human. It is the best and most used captcha system available where users are only required to click on a checkbox and in some cases select some similar images related to the conman question.
In this example, we will create a simple registration form and implement a google captcha code. before using google captcha code we will install "josiasmontag/laravel-recaptchav3" composer package for google captcha. You have to just follow a few steps and you will get google re-captcha code in your laravel 9 app.
Step 1: Install Laravel 9
This is optional; however, if you have not created the laravel app, then you may go ahead and execute the below command:
In this step we need to set google site key and secret key. If you don't have site key and secret key then you can create from here. First click on this link : Recaptcha Admin
Now you have to create new key for google recaptchav3 as bellow screen shot:
In this step, we have to create new controller as RegisterController and we have also need to add two methods index() and store() on that controller like as you can see bellow:
app/Http/Controllers/RegisterController.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; class RegisterController extends Controller{ /** * Create a new controller instance. * * @return void */ public function index() { return view('register'); } /** * Create a new controller instance. * * @return void */ public function store(Request $request) { $this->validate($request, [ 'name' => 'required', 'email' => 'required|email', 'password' => 'required|same:password_confirmation', 'password_confirmation' => 'required', 'g-recaptcha-response' => 'required|recaptchav3:register,0.5' ]); dd('done'); }}
Step 5: Create Route
We need to create register routes as bellow:
routes/web.php
<?php use Illuminate\Support\Facades\Route;use App\Http\Controllers\RegisterController; /*|--------------------------------------------------------------------------| Web Routes|--------------------------------------------------------------------------|| Here is where you can register web routes for your application. These| routes are loaded by the RouteServiceProvider within a group which| contains the "web" middleware group. Now create something great!|*/ Route::controller(RegisterController::class)->group(function(){ Route::get('register', 'index'); Route::post('register', 'store');});
Step 6: Create View File
In Last step, let's create register.blade.php(resources/views/register.blade.php) for layout and lists all items code here and put following code: