### 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
{!! 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