定制 msglaravel/yandex-smart-captcha 二次开发

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

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

msglaravel/yandex-smart-captcha

最新稳定版本:v1.0.2

Composer 安装命令:

composer require msglaravel/yandex-smart-captcha

包简介

Yandex captcha integration for Laravel

README 文档

README

Total Downloads Latest Stable Version License

Laravel package for Yandex Smart Captcha. This is a lightweight package which focuses on the backend validation of Yandex Smart Captcha.

Installation

To get started, use Composer to add the package to your project's dependencies:

composer require msglaravel/yandex-smart-captcha

Add to your .env file:

YANDEX_SMARTCAPTCHA_ENDPOINT=https://smartcaptcha.cloud.yandex.ru
YANDEX_SMARTCAPTCHA_SITEKEY=sitekey
YANDEX_SMARTCAPTCHA_SECRET=secret

Optionally, you can publish the config file:

php artisan vendor:publish --provider="MSGLaravel\YandexSmartCaptcha\YandexSmartCaptchaServiceProvider"

Usage

Init Recaptcha Javascript

Желательно добавлять скрипт вызова библиотеки Yandex Smart Captcha в самом верху страницы. Например, в вашем header Blade-шаблоне:

@yandexSmartCaptchaScript                  {{-- Basic use --}}
@yandexSmartCaptchaScript('myOnloadCb')    {{-- With custom onload callback --}}

Forms

Insert the captcha widget into your form using Blade include:

    @include('yandex-smart-captcha::captcha')

If you need a version with a custom onload function, use:

    @include('yandex-smart-captcha::captcha-extend')

Use it together with @yandexSmartCaptchaScript('onloadFunction').

<form method="post" action="/register">
    @include('yandex-smart-captcha::captcha')
    <input type="submit" value="Register"></input>
</form>

Validation

In your controller:

use MSGLaravel\YandexSmartCaptcha\Rules\YandexSmartCaptchaRule;

$request->validate([
    // ...
    'smart-token' => ['required', new YandexSmartCaptchaRule()],
]);

You can customize the error message for the captcha in your controller (applies to all errors of this rule):

use MSGLaravel\YandexSmartCaptcha\Rules\YandexSmartCaptchaRule;

$request->validate(
    [
        'smart-token' => ['required', new YandexSmartCaptchaRule()],
    ],
    [
        'smart-token' => 'Ошибка проверки капчи. Попробуйте ещё раз.',
    ]
);

Advanced

Override templates: Copy captcha.blade.php or captcha-extend.blade.php from resources/views/vendor/yandex-smart-captcha/ to your project for full customization.

Localization & Custom Error Messages

This package includes localized validation error messages for Yandex Smart Captcha in both Russian and English.

If you want to customize error messages for your project, publish the language files to your application:

php artisan vendor:publish --provider="MSGLaravel\YandexSmartCaptcha\YandexSmartCaptchaServiceProvider" --tag=lang

This command will copy the language files to:

resources/lang/vendor/yandex-smart-captcha/ru/validation.php
resources/lang/vendor/yandex-smart-captcha/en/validation.php

You can now edit these files to override any validation error messages as needed.

Note:

Laravel will use your published files in resources/lang/vendor/yandex-smart-captcha instead of the package defaults.

统计信息

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

GitHub 信息

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

其他信息

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