定制 sushantaryal/laravel-recaptcha 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sushantaryal/laravel-recaptcha

最新稳定版本:1.0.1

Composer 安装命令:

composer require sushantaryal/laravel-recaptcha

包简介

A Laravel package to validate google recaptcha v3

README 文档

README

A Laravel package for validating Google Recaptcha v3.

Installation

You can install the package via Composer:

composer require sushantaryal/laravel-recaptcha

Getting reCAPTCHA keys

Follow the official documentation to get the reCAPTCHA site key and secret key.

Configuration

Add these to your .env:

RECAPTCHA_KEY=
RECAPTCHA_SECRET=
RECAPTCHA_THRESHOLD=0.5

Usage

Form

Follow the official documentation to get the reCAPTCHA HTML code.

Automatically bind the challenge to a button

<script src="https://www.google.com/recaptcha/api.js"></script>

Add a callback function to handle the token.

<script>
    function onSubmit(token) {
        document.getElementById("demo-form").submit();
    }
</script>

Add attributes to your html button.

<button
    class="g-recaptcha"
    data-sitekey="{{ config('recaptcha.key') }}"
    data-callback="onSubmit"
    data-action="submit"
>
    Submit
</button>

OR

Programmatically invoke the challenge

Use the <x-recaptcha::input /> in your form.

<form action="" method="post" id="recaptcha-form">
    @csrf
    <!-- Add for form inputs -->
    <x-recaptcha::input />
    <button type="submit">Submit</button>
</form>

Load the JavaScript with the recaptcha blade component before closing body tag.

<body>
    ...
    <x-recaptcha::script :formId="'recaptcha-form'" :action="'submit'" />
</body>

Backend

You can use the Recaptcha rule in your validation rules:

use Sushant\LaravelRecaptcha\Rules\Recaptcha;

$request->validate([
    'g-recaptcha-response' => ['required', new Recaptcha()],
]);

License

MIT license.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-16