scaffold-digital/laravel-recaptcha 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

scaffold-digital/laravel-recaptcha

Composer 安装命令:

composer require scaffold-digital/laravel-recaptcha

包简介

Google Recaptcha module for Laravel

README 文档

README

This module is an easy to use implementation of the Google reCAPTCHA widget.

Getting Started

To use this package, simply install with Composer. Once installed, you'll need to specify your site key and secret key (from https://www.google.com/recaptcha/admin) and then follow a couple of simple steps to add the recaptcha widget to your view and verify the response.

Installing via Composer

To install the module, simply run the following command in your project directory...

composer require scaffold-digital/laravel-recaptcha

Setting up your keys

Once you retrieved your site key and secret key (from https://www.google.com/recaptcha/admin), you'll need to specify them in a config file.

Basic configuration

For the most basic configuration, create the file "config/recaptcha.php" and paste the following contents, changing the keys accordingly...

<?php
return [
    'key' => 'YOUR SITE KEY',
    'secret' => 'YOUR SECRET KEY',
];

Advanced configuration

If you'd like to extend the Recaptcha feature further, you can do so easily by publishing the full configuration and modifying it accordingly. Running the following command will allow you to publish the full configuration to your config directory.

php artisan vendor:publish

Displaying the reCAPTCHA widget

In order to display the reCAPTCHA widget in your view, you'll need to include an additional piece of Javascript and a DOM element. Both of these are available through the Recaptcha class.

The Javascript

Simply add {!! Recaptcha::getScript(); !!} just before the closing <head> tag:

<head>
...
{!! Recaptcha::getScript(); !!}
</head>

The Widget

Just add {!! Recaptcha::getWidget(); !!} wherever you'd like to display the widget in your form. For example:

<body>
...
<form method="POST">
<div class="form-group">{!! Recaptcha::getWidget(); !!}</div>
</form>
...
</body>

Validating the reCAPTCHA response

You have two straightforward options to validate the reCAPTCHA response. This can be done manually at any point or automatically as part of Laravel's built-in form validation.

Automatic Form Validation

This package automatically creates a new validation type for 'recaptcha' that you can use to validate the form response. When the form is submitted, reCAPTCHA uses the field 'g-recaptcha-response' to provide the response. For example:

$validator = Validator::make($request->all(), [
    'g-recaptcha-response' => 'recaptcha'
]);

Manual Validation

If for whatever reason you'd like to validate the reCAPTCHA response manually, you can do so simply by calling the verify method. For example:

$valid = Recaptcha::verify($request->input('g-recaptcha-response'));

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2018-07-31

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固