### Install Laravel Google reCAPTCHA V3 via Composer Source: https://github.com/ryandadeng/laravel-google-recaptcha-v3/blob/master/README.md Installs the latest version of the Laravel Google reCAPTCHA V3 package using Composer. This is the primary method for adding the package to your Laravel project. ```Bash $ composer require timehunter/laravel-google-recaptcha-v3 "~2.5" ``` -------------------------------- ### Refreshing reCAPTCHA Token Source: https://github.com/ryandadeng/laravel-google-recaptcha-v3/blob/master/README.md Example of how to programmatically refresh the reCAPTCHA token using the component's execute method, typically called after a form submission. ```vue this.$refs.captcha.execute(); ``` -------------------------------- ### Ajax Usage - Refresh reCAPTCHA Response Source: https://github.com/ryandadeng/laravel-google-recaptcha-v3/blob/master/README.md Provides JavaScript functions `refreshReCaptchaV3(fieldId, actionName)` and `getReCaptchaV3Response(id)` for managing reCAPTCHA responses in AJAX requests. The example shows how to retrieve the response and refresh it upon AJAX success or error. ```html ``` -------------------------------- ### Facade Usage for reCAPTCHA Verification Source: https://github.com/ryandadeng/laravel-google-recaptcha-v3/blob/master/README.md Demonstrates how to use the GoogleReCaptchaV3 facade to set actions, verify responses with tokens and IP addresses, and retrieve messages or check success status. ```PHP GoogleReCaptchaV3::setAction($action)->verifyResponse($value,$ip = null); ``` ```PHP GoogleReCaptchaV3::verifyResponse($value,$ip)->getMessage(); GoogleReCaptchaV3::verifyResponse($value)->isSuccess(); GoogleReCaptchaV3::verifyResponse($value)->toArray(); ``` ```PHP GoogleReCaptchaV3::verifyResponse( $request->input('g-recaptcha-response'), $request->getClientIp() ) ->getMessage() ``` ```PHP GoogleReCaptchaV3::setAction($action)->verifyResponse($value)->isSuccess(); ``` ```PHP GoogleReCaptchaV3::setScore($score) ->setAction($action) ->verifyResponse( $request->input('g-recaptcha-response'), $request->getClientIp() ) ->getMessage() ``` -------------------------------- ### Publish Language Files for Laravel Google reCAPTCHA V3 Source: https://github.com/ryandadeng/laravel-google-recaptcha-v3/blob/master/README.md Publishes the language files for the Laravel Google reCAPTCHA V3 package, enabling multi-language support. This creates a lang folder under /resources/lang/vendor/GoogleReCaptchaV3. ```Bash $ php artisan vendor:publish --provider="TimeHunter\LaravelGoogleReCaptchaV3\Providers\GoogleReCaptchaV3ServiceProvider" --tag=googlerecaptchav3.lang ``` -------------------------------- ### Custom reCAPTCHA Configuration Implementation Source: https://github.com/ryandadeng/laravel-google-recaptcha-v3/blob/master/README.md Shows how to implement a custom configuration provider by implementing the ReCaptchaConfigV3Interface and registering it in the service provider. ```php $this->app->bind( TimeHunter\LaravelGoogleReCaptchaV3\Interfaces\ReCaptchaConfigV3Interface::class, YourOwnCustomImplementation::class ); ``` -------------------------------- ### Publish Laravel Google reCAPTCHA V3 Configuration Source: https://github.com/ryandadeng/laravel-google-recaptcha-v3/blob/master/README.md Publishes the configuration file for the Laravel Google reCAPTCHA V3 package using the Artisan command. This command is used for Laravel versions 5.5 and above. ```Bash $ php artisan vendor:publish --provider="TimeHunter\LaravelGoogleReCaptchaV3\Providers\GoogleReCaptchaV3ServiceProvider" --tag=googlerecaptchav3.config ``` -------------------------------- ### Publish Vue Component for reCAPTCHA v3 Source: https://github.com/ryandadeng/laravel-google-recaptcha-v3/blob/master/README.md Explains how to publish the Vue.js component for Google reCAPTCHA v3 using an Artisan command. This makes the `GoogleReCaptchaV3.vue` file available in the `js/components/googlerecaptchav3/` directory for customization. ```sh $ php artisan vendor:publish --provider="TimeHunter\LaravelGoogleReCaptchaV3\Providers\GoogleReCaptchaV3ServiceProvider" --tag=googlerecaptchav3.vuejs ``` -------------------------------- ### Hardcoding Site Key in Component Source: https://github.com/ryandadeng/laravel-google-recaptcha-v3/blob/master/README.md Illustrates modifying the Vue component to hardcode the site key directly, simplifying configuration for static site keys. ```vue siteKey: { type: String, required: false, // set to true if you don't want to store the siteKey in this component default: 'Your Site Key Here' // set siteKey here if you want to store it in this component }, ``` -------------------------------- ### Custom Request Method Implementation Source: https://github.com/ryandadeng/laravel-google-recaptcha-v3/blob/master/README.md Demonstrates how to implement a custom request client by implementing the RequestClientInterface and registering it in the service provider for custom verification requests. ```php $this->app->bind( TimeHunter\LaravelGoogleReCaptchaV3\Interfaces\RequestClientInterface::class, YourOwnCustomImplementation::class ); ``` -------------------------------- ### Configure reCAPTCHA v3 Settings Source: https://github.com/ryandadeng/laravel-google-recaptcha-v3/blob/master/README.md Specify score thresholds and actions in the Laravel configuration file. This includes settings for score comparison and enabling score verification. ```PHP 'setting' = [ [ 'action' => 'contact_us', 'threshold' => 0.2, 'score_comparison' => false ], [ 'action' => 'signup', 'threshold' => 0.2, 'score_comparison' => true ], ] ``` ```PHP ... 'is_score_enabled' = true ... ``` ```PHP ... 'background_badge_display' => true, 'background_mode' => false, ... ``` -------------------------------- ### Render Single reCAPTCHA v3 in Laravel Forms (renderOne) Source: https://github.com/ryandadeng/laravel-google-recaptcha-v3/blob/master/README.md Shows how to use the `renderOne()` method to render a single reCAPTCHA instance in a form. This method takes the div ID and the action name as parameters. Ensure a div with the specified ID exists in your HTML form. ```PHP GoogleReCaptchaV3::renderOne($id,$action); ``` ```Blade {!! GoogleReCaptchaV3::renderOne('contact_us_id','contact_us') !!} ``` ```HTML
// add div with id
{!! GoogleReCaptchaV3::renderOne('contact_us_id','contact_us') !!} ``` -------------------------------- ### Include Google reCAPTCHA v3 API Script Source: https://github.com/ryandadeng/laravel-google-recaptcha-v3/blob/master/README.md Includes the Google API script in the Blade layout to initialize reCAPTCHA v3. Supports adding a nonce for Content Security Policy. ```HTML {!! GoogleReCaptchaV3::init() !!} ``` ```HTML {!! GoogleReCaptchaV3::init([ 'nonce' => nonce(), ]) !!} ``` -------------------------------- ### Vue.js Integration of reCAPTCHA v3 Component Source: https://github.com/ryandadeng/laravel-google-recaptcha-v3/blob/master/README.md Demonstrates how to use the Vue.js component for reCAPTCHA v3. It shows how to import and register the component, and pass props like `siteKey`, `id`, `inline`, and `action`. The `v-model` directive is used to bind the CAPTCHA response. ```vue ``` -------------------------------- ### Render reCAPTCHA v3 in Laravel Forms (render) Source: https://github.com/ryandadeng/laravel-google-recaptcha-v3/blob/master/README.md Demonstrates how to use the `render()` method to populate reCAPTCHA within a form. This method accepts an array of IDs and actions to render multiple CAPTCHAs. It requires a corresponding div element with the specified ID in the HTML form. ```Blade {!! GoogleReCaptchaV3::render(['contact_us_id'=>'contact_us', 'signup_id'=>'signup']) !!} ``` ```HTML
// add div with id
{!! GoogleReCaptchaV3::render(['contact_us_id'=>'contact_us', 'signup_id'=>'signup']) !!} ``` -------------------------------- ### Vue Component Integration with reCAPTCHA v3 Source: https://github.com/ryandadeng/laravel-google-recaptcha-v3/blob/master/README.md Demonstrates how to use the GoogleReCaptchaV3 Vue component in a form. It shows how to bind the reCAPTCHA response, set the site key, and refresh the token upon form submission. ```vue ``` -------------------------------- ### Register Service Provider and Alias in Laravel <= 5.4 Source: https://github.com/ryandadeng/laravel-google-recaptcha-v3/blob/master/README.md Manually registers the Google reCAPTCHA V3 service provider and creates an alias for the facade in the `config/app.php` file for Laravel versions 5.4 and below. ```PHP 'providers'=> [ ...., TimeHunter\LaravelGoogleReCaptchaV3\Providers\GoogleReCaptchaV3ServiceProvider::class ] ``` ```PHP 'aliases'=> [ ...., 'GoogleReCaptchaV3'=> TimeHunter\LaravelGoogleReCaptchaV3\Facades\GoogleReCaptchaV3::class ] ``` -------------------------------- ### Blade Template with reCAPTCHA v3 Source: https://github.com/ryandadeng/laravel-google-recaptcha-v3/wiki/Simple-Demo This Blade file includes the necessary JavaScript for reCAPTCHA v3 and demonstrates rendering reCAPTCHA fields for both a standard HTML form and an AJAX-triggered form. It also includes jQuery for handling the AJAX request. ```html Test
Normal Form
@csrf {!! GoogleReCaptchaV3::renderField('contact_us_id','contact_us_action') !!}

Ajax Form
@csrf {!! GoogleReCaptchaV3::renderField('contact_us_ajax_id','contact_us_action') !!}
{!! GoogleReCaptchaV3::init() !!} ``` -------------------------------- ### Invisible reCAPTCHA Badge Display Source: https://github.com/ryandadeng/laravel-google-recaptcha-v3/blob/master/README.md Details the steps for configuring an invisible reCAPTCHA badge. This involves setting `inline` to `true`, hiding the CAPTCHA div using CSS (`display:none`), and including specific disclaimer text with links to Google's Privacy Policy and Terms of Service. ```HTML This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply. ``` -------------------------------- ### Validation Rule for reCAPTCHA Source: https://github.com/ryandadeng/laravel-google-recaptcha-v3/blob/master/README.md Shows how to use the provided Validation object to create a validation rule for the reCAPTCHA response field in Laravel. ```PHP use TimeHunter\LaravelGoogleReCaptchaV3\Validations\GoogleReCaptchaV3ValidationRule; $rule = [ 'g-recaptcha-response' => [new GoogleReCaptchaV3ValidationRule('action_name')] ]; ``` -------------------------------- ### Publish Vue Component for Laravel Google reCAPTCHA V3 Source: https://github.com/ryandadeng/laravel-google-recaptcha-v3/blob/master/README.md Publishes the Vue.js component for the Laravel Google reCAPTCHA V3 package. This allows for easy integration of reCAPTCHA into Vue.js applications within a Laravel project. ```Bash $ php artisan vendor:publish --provider="TimeHunter\LaravelGoogleReCaptchaV3\Providers\GoogleReCaptchaV3ServiceProvider" --tag=googlerecaptchav3.vuejs ``` -------------------------------- ### Configure reCAPTCHA v3 Credentials Source: https://github.com/ryandadeng/laravel-google-recaptcha-v3/blob/master/README.md Register your Google reCAPTCHA v3 secret key and site key in the .env file for the application. ```dotenv RECAPTCHA_V3_SECRET_KEY= RECAPTCHA_V3_SITE_KEY= ``` -------------------------------- ### Laravel Route for reCAPTCHA v3 Verification Source: https://github.com/ryandadeng/laravel-google-recaptcha-v3/wiki/Simple-Demo This PHP code defines a POST route '/verify' that uses a custom validation rule, `GoogleReCaptchaV3ValidationRule`, to validate the 'g-recaptcha-response' token. It demonstrates how to integrate server-side validation for reCAPTCHA. ```php use TimeHunter\LaravelGoogleReCaptchaV3\Validations\GoogleReCaptchaV3ValidationRule; Route::get('/', function (\Illuminate\Http\Request $request) { return view('welcome'); }); Route::post('/verify', function (\Illuminate\Http\Request $request) { $rule = [ 'g-recaptcha-response' => [new GoogleReCaptchaV3ValidationRule('contact_us_action')] ]; $validator = \Illuminate\Support\Facades\Validator::make($request->toArray(),$rule)->errors(); dd($validator->toArray()); }); ``` -------------------------------- ### Configure Inline reCAPTCHA Badge Display Source: https://github.com/ryandadeng/laravel-google-recaptcha-v3/blob/master/README.md Explains how to set the `inline` configuration option to `true` in the Laravel config file to display the reCAPTCHA badge inline within the form. This requires clearing the config cache after modification. ```PHP [ ... 'inline' => true ... ] ``` -------------------------------- ### Render reCAPTCHA v3 Field in Laravel Forms (renderField) Source: https://github.com/ryandadeng/laravel-google-recaptcha-v3/blob/master/README.md Illustrates using the `renderField()` method to render a reCAPTCHA field directly within a form. This method accepts the div ID, action, and optional class and style parameters. The CAPTCHA will be embedded within the specified div. ```PHP GoogleReCaptchaV3::renderField($id,$action,$class,$style) ``` ```Blade {!! GoogleReCaptchaV3::renderField('contact_us_id','contact_us_action') !!} ``` ```HTML
{!! GoogleReCaptchaV3::renderField('contact_us_id','contact_us_action') !!}
``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.