{"id":15016815,"url":"https://github.com/dutchcodingcompany/livewire-recaptcha","last_synced_at":"2026-04-12T23:01:46.988Z","repository":{"id":242678769,"uuid":"808561348","full_name":"DutchCodingCompany/livewire-recaptcha","owner":"DutchCodingCompany","description":"Add Livewire reCAPTCHA form validation to your components.","archived":false,"fork":false,"pushed_at":"2025-01-27T03:41:13.000Z","size":38,"stargazers_count":20,"open_issues_count":2,"forks_count":5,"subscribers_count":3,"default_branch":"development","last_synced_at":"2025-04-11T15:16:39.396Z","etag":null,"topics":["laravel","livewire","recaptcha-v3"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DutchCodingCompany.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-31T10:21:59.000Z","updated_at":"2025-03-28T20:20:53.000Z","dependencies_parsed_at":"2024-06-04T11:55:41.746Z","dependency_job_id":"ada3ecf8-e6fe-412d-9c28-44f3fe8fbf9f","html_url":"https://github.com/DutchCodingCompany/livewire-recaptcha","commit_stats":null,"previous_names":["dutchcodingcompany/livewire-recaptcha"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DutchCodingCompany%2Flivewire-recaptcha","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DutchCodingCompany%2Flivewire-recaptcha/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DutchCodingCompany%2Flivewire-recaptcha/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DutchCodingCompany%2Flivewire-recaptcha/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DutchCodingCompany","download_url":"https://codeload.github.com/DutchCodingCompany/livewire-recaptcha/tar.gz/refs/heads/development","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248557104,"owners_count":21124156,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","livewire","recaptcha-v3"],"created_at":"2024-09-24T19:49:25.252Z","updated_at":"2026-04-12T23:01:46.966Z","avatar_url":"https://github.com/DutchCodingCompany.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Livewire ReCAPTCHA v3/v2/v2-invisible\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/dutchcodingcompany/livewire-recaptcha.svg?style=flat-square)](https://packagist.org/packages/dutchcodingcompany/livewire-recaptcha)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/dutchcodingcompany/livewire-recaptcha/run-tests.yml?branch=main\u0026label=tests)](https://github.com/dutchcodingcompany/livewire-recaptcha/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/dutchcodingcompany/livewire-recaptcha/php-cs-fixer.yml?branch=main\u0026label=style)](https://github.com/dutchcodingcompany/livewire-recaptcha/actions?query=workflow%3A\"Check+%26+fix+styling\"+branch%3Amain)\n[![GitHub PHPStan Action Status](https://img.shields.io/github/actions/workflow/status/dutchcodingcompany/livewire-recaptcha/phpstan.yml?branch=main\u0026label=phpstan)](https://github.com/DutchCodingCompany/livewire-recaptcha/actions?query=workflow%3APHPStan++branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/dutchcodingcompany/livewire-recaptcha.svg?style=flat-square)](https://packagist.org/packages/dutchcodingcompany/livewire-recaptcha)\n\nThis package provides a custom Livewire directive to protect your Livewire functions with a _Google reCAPTCHA (v2 + v2\ninvisible + v3)_ check.\n\n## Installation\n\n```shell\ncomposer require dutchcodingcompany/livewire-recaptcha\n```\n\n## Configuration\n\nRead https://developers.google.com/recaptcha/intro on how to create your own key pair for the specific ReCaptcha\nversion you are going to implement.\n\nThis package supports the following versions. Note that each version requires a different sitekey/secretkey pair:\n\n| **Version**          | **Docs**                                                          | **Notes**                         |\n|----------------------|-------------------------------------------------------------------|-----------------------------------|\n| **v3** (recommended) | [V3 Docs](https://developers.google.com/recaptcha/docs/v3)        |                                   |\n| **v3** (enterprise)  | [V3 Docs](https://developers.google.com/recaptcha/docs/v3)        | Use `'version' =\u003e 'v3-enterprise'` |\n| **v2**               | [V2 Docs](https://developers.google.com/recaptcha/docs/display)   |                                   |\n| **v2 invisible**     | [V2 Docs](https://developers.google.com/recaptcha/docs/invisible) | Use `'size' =\u003e 'invisible'`       |\n\nYour options should reside in the `config/services.php` file:\n\n```php\n    // V3 config:\n    'google' =\u003e [\n        'recaptcha' =\u003e [\n            'site_key' =\u003e env('GOOGLE_RECAPTCHA_SITE_KEY'),\n            'secret_key' =\u003e env('GOOGLE_RECAPTCHA_SECRET_KEY'),\n            'version' =\u003e 'v3',\n            'score' =\u003e 0.5, // An integer between 0 and 1, that indicates the minimum score to pass the Captcha challenge.\n            'endpoint' =\u003e 'https://www.google.com/recaptcha/api/siteverify', // For enterprise users, fill in your URL from Google Console.\n        ],\n    ],\n\n    // V2 config:\n    'google' =\u003e [\n        'recaptcha' =\u003e [\n            'site_key' =\u003e env('GOOGLE_RECAPTCHA_SITE_KEY'),\n            'secret_key' =\u003e env('GOOGLE_RECAPTCHA_SECRET_KEY'),\n            'version' =\u003e 'v2',\n            'size' =\u003e 'normal', // 'normal', 'compact' or 'invisible'.\n            'theme' =\u003e 'light', // 'light' or 'dark'.\n        ],\n    ],\n```\n\n#### Component\n\nIn your Livewire component, at your form submission method, add the `#[ValidatesRecaptcha]` attribute:\n\n```php\nuse Livewire\\Component;\nuse DutchCodingCompany\\LivewireRecaptcha\\ValidatesRecaptcha;\n\nclass SomeComponent extends Component \n{\n    // (optional) Set a response property on your component.\n    // If not given, the `gRecaptchaResponse` property is dynamically assigned.\n    public string $gRecaptchaResponse;\n    \n    #[ValidatesRecaptcha]\n    public function save(): mixed\n    {\n        // Your logic here will only be called if the captcha passes...\n    }\n}\n```\n\nFor fine-grained control, you can pass a custom secret key and minimum score (applies only to V3) using:\n\n```php\n#[ValidatesRecaptcha(secretKey: 'mysecretkey', score: 0.9)]\n```\n\n#### View\n\nOn the view side, you have to include the Blade directive `@livewireRecaptcha`. This adds two scripts to the page,\none for the reCAPTCHA script and one for the custom Livewire directive to hook into the form submission.\n\nPreferrably these scripts are only added to the page that has the Captcha-protected form (alternatively, you can add\nthe `@livewireRecaptcha` directive on a higher level, lets say your layout).\n\nSecondly, add the new directive `wire:recaptcha` to the form element that you want to protect.\n\n```html\n\u003c!-- some-livewire-component.blade.php --\u003e\n\n\u003c!-- (optional) Add error handling --\u003e\n@if($errors-\u003ehas('gRecaptchaResponse'))\n\u003cdiv class=\"alert alert-danger\"\u003e{{ $errors-\u003efirst('gRecaptchaResponse') }}\u003c/div\u003e\n@endif\n\n\u003c!-- Add the `wire:recaptcha` Livewire directive --\u003e\n\u003cform wire:submit=\"save\" wire:recaptcha\u003e\n    \u003c!-- The rest of your form --\u003e\n\n    \u003c!-- When using version 2, insert the placeholder element --\u003e\n    \u003cdiv id=\"g-recaptcha-element\"\u003e\u003c/div\u003e\n\n    \u003cbutton type=\"submit\"\u003eSubmit\u003c/button\u003e\n\u003c/form\u003e\n\n\u003c!-- Add the `@livewireRecaptcha` Blade directive --\u003e\n@livewireRecaptcha\n```\n\nYou can override any of the configuration values using:\n\n```html\n@livewireRecaptcha(\n    version: 'v2',\n    siteKey: 'abcd_efgh-hijk_LMNOP',\n    theme: 'dark',\n    size: 'compact',\n)\n```\n\n#### Finishing up\n\nThe Google ReCAPTCHA validation will automatically occur before the actual form is submitted. Before the `save()` method\nis executed, a serverside request will be sent to Google to verify the Captcha challenge. Once the reCAPTCHA\nresponse has been successful, your actual Livewire component method will be executed.\n\n#### Error handling\n\nWhen an error occurs with the Captcha validation, a ValidationException is thrown for the key `gRecaptchaResponse`.\nThere is a translatable error message available under `'livewire-recaptcha::recaptcha.invalid_response'`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdutchcodingcompany%2Flivewire-recaptcha","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdutchcodingcompany%2Flivewire-recaptcha","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdutchcodingcompany%2Flivewire-recaptcha/lists"}