tutorials/recaptcha3

There is no license information available for the latest version (1.0.2) of this package.

Google recaptcha v3 integration for laravel/inertia

1.0.2 2024-01-21 13:09 UTC

This package is not auto-updated.

Last update: 2024-11-11 15:34:29 UTC


README

  1. Install composer package
composer require tutorials/recaptcha3
  1. Define service provider in config/app.php
'providers' => [
    ...
    Tutorials\Recaptcha3\RecaptchaServiceProvider::class
],
  1. Define variables in .env file and put values from recaptcha admin panel
RECAPTCHA_ENABLED=
RECAPTCHA_SITE_KEY=
RECAPTCHA_SECRET_KEY=
  1. Put recaptcha middleware on route
Route::post('/login', LoginController::class)->middleware('recaptcha');
Route::post('/register', LoginController::class)->middleware('recaptcha:0.6');
  1. Insert @recaptcha blade directive in the layout
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Recaptcha</title>
        
        @recaptcha
    </head>
</html>
  1. Wrap your form submit logic with recaptcha validation
window.recaptcha('action_name_for_recaptcha_statistic').then((token) => {
    // form submition logic
    form.transform((data) => ({
        ...data,
        recaptcha_token: token, // recaptcha_token is required
    })).post(route('login'))
});
  1. Run php artisan view:clear to clear the view cache