承接 origami/captcha 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

origami/captcha

Composer 安装命令:

composer require origami/captcha

包简介

Simple Google Recaptcha integration for Laravel projects

README 文档

README

This package adds a validation rule and controller trait for easier integration with Google Recaptcha

Installation

Install this package through Composer.

composer require origami/captcha

Requirements

This package is designed to work with Laravel >= 10 currently. If you require 5.8 support, use version 1. If you require 6-7 support use version 2.

Setup

  1. Signup for a Google Recaptcha account at https://www.google.com/recaptcha/admin

  2. You should add a recatpcha section to your config/services.php file:

    
    'recaptcha' => [
        'key' => env('RECAPTCHA_KEY'),
        'secret' => env('RECAPTCHA_SECRET'),
    ],
  1. Update your .env file with the key and secret:
RECAPTCHA_KEY=
RECAPTCHA_SECRET=
  1. Add a language line to your validation file(s), e.g. resources/lang/en/validation.php

    'recaptcha' => 'The reCAPTCHA check was invalid',

Usage

Validator

$validator = Validator::make($request->all(), [
    'recaptcha' => [new Origami\Captcha\Rules\Recaptcha],
]);

Controller Validation

(Assuming your Controller has the ValidatesRequests trait)

class Contact extends Controller
{
    public function store(Request $request)
    {
        $this->validate($request, [
            'recatpcha' => [new Origami\Captcha\Rules\Recaptcha]
        ]);
    }
}

Changing Google secret

If you have multiple Recaptcha secrets (e.g. for different versions), you can customise in the rule params. Otherwise it will default to config('services.recaptcha.secret')

class Contact extends Controller
{
    public function store(Request $request)
    {
        $this->validate($request, [
            'recatpcha' => [new Origami\Captcha\Rules\Recaptcha(secret: '123')]
        ]);
    }
}

Controller with ValidatesCaptcha Trait

use Origami\Captcha\ValidatesCaptcha;

class Contact extends Controller
{
    use ValidatesCaptcha;

    public function store(Request $request)
    {
        $this->validateRecaptcha($request);

        // The above will throw a ValidationException when the recaptcha fails.
    }

}

Blade Helpers

This packages registers two Blade helpers:

@recaptchaField is the equivalent of:

<div class="g-recaptcha" data-sitekey="{{ config('services.recaptcha.key') }}"></div>

@recaptchaScript is the equivalent of:

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

Upgrading

From v2 to v3

Version 3 was created to add Laravel 11.x support and drop support for Laravel versions before 10.x. This is a breaking change as the package now relies on Rule Objects.

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

// After
$validator = Validator::make($request->all(), [
    'recaptcha' => [new Origami\Captcha\Rules\Recaptcha],
]);

The ValidatesCaptcha trait validateReCaptcha method has been renamed validateRecaptcha

Author

License

MIT License

origami/captcha 适用场景与选型建议

origami/captcha 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.21k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2018 年 09 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 origami/captcha 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 origami/captcha 我们能提供哪些服务?
定制开发 / 二次开发

基于 origami/captcha 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-09-20