hirenkeraliya/lara-captcha

Laravel自定义recaptcha。

2.1 2023-03-14 15:38 UTC

This package is auto-updated.

Last update: 2024-09-14 19:04:19 UTC


README

Laravel Captcha (Laravel 9.x)

Lara-Captcha 是一个可靠且易于使用的包,用于防止机器人提交并增强 Laravel 中公共表单的安全性。凭借其简单的集成和多种自定义选项,它是开发者提高表单安全性的理想选择。

要求

功能

  • 与 Laravel 表单的简单集成
  • 支持多种配置以进行自定义
  • 提供有效防止机器人提交的保护
  • 实现所需的代码更改最少
  • 作者定期更新和修复错误
  • 轻量级包,高效性能

用法

以下是在 Laravel 表单中使用 Lara-Captcha 的示例

  <form method="POST" action="/submit-form">
    @csrf
    @captcha

    <input type="text" name="name" placeholder="Name"><br>
    <input type="email" name="email" placeholder="Email"><br>
    <button type="submit">Submit</button>
  </form>

安装

按照以下步骤安装包

  1. 在您的终端/cmnd 中运行以下命令
composer require hirenkeraliya/lara-captcha
  1. 通过在终端/cmnd 中运行此命令导入配置文件
php artisan vendor:publish --tag=lara-captcha-config
  1. 在表单中 CSRF 令牌后添加 @captcha

  2. 要使用中间件,请将以下行添加到您的路由中

use Hirenkeraliya\LaraCaptcha\app\Http\Middleware\VerifyCaptcha;

Route::post('contact-us', [ContactUsController::class, 'index'])->name('front.contact_us')->middleware(VerifyCaptcha::class);

或您可以通过使用路由分组将其应用于多个路由。

use Hirenkeraliya\LaraCaptcha\app\Http\Middleware\VerifyCaptcha;

Route::group(['middleware' => VerifyCaptcha::class], function () {
  Route::post('contact-us', [ContactUsController::class, 'index'])->name('front.contact_us');
});

Route::middleware([VerifyCaptcha::class])->group(function () {
  Route::post('contact-us', [ContactUsController::class, 'index'])->name('front.contact_us');
});

就这些!您的表单现在可以抵御机器人提交了。

配置

Lara-Captcha 提供了多种配置选项,您可以修改以符合您的需求。默认配置可以在运行 vendor:publish 命令后找到 config/lara-captcha.php 文件。

您可以修改以下配置选项

  • enabled:验证可以启用或禁用。
  • input_name:表单中输入字段的名称。
  • error.message:检测到机器人提交时显示的错误消息。
  • error.status_code:检测到机器人提交时显示的错误状态码。

作者

支持

如果您在 Lara-Captcha 中遇到任何问题或有改进建议,请随时在 GitHub 存储库 上提出问题。

贡献

Lara-Captcha 欢迎所有贡献!要贡献,只需分支存储库,进行更改,然后提交拉取请求。

许可证

本项目采用 MIT 许可证 - 有关详细信息,请参阅 LICENSE 文件

特别感谢

特别感谢 Laravel 社区对他们支持