fungku/spamguard

保护表单请求免受垃圾邮件机器人侵害。

v0.2.0 2016-01-25 18:38 UTC

This package is auto-updated.

Last update: 2024-08-28 22:53:01 UTC


README

保护表单请求免受机器人侵害。

Version License Downloads Quality Travis

安装

composer require fungku/spamguard

将服务提供者添加到 config/app.php 中的 providers 数组

Fungku\SpamGuard\Providers\SpamGuardServiceProvider::class,

将别名添加到 config/app.php 中的 aliases 数组

'SpamGuard' => Fungku\SpamGuard\Facades\SpamGuard::class,

配置(可选)

如果您想更改默认的包配置值,则发布配置并更改默认值...

php artisan vendor:publish --provider="Fungku\SpamGuard\Providers\SpamGuardConfigServiceProvider" --tag="config"

使用方法

要使用 spamguard,您需要做两件事。

1. 在您的表单中添加 SpamGuard 表单元素

在表单的某个位置,只需使用 SpamGuard::html()

使用所有 spam guard 元素

<form action="/some-route/action">

    {!! SpamGuard::html() !!}

    <!-- other form elements -->

</form>

指定特定元素

<form action="/some-route/action">

    {!! SpamGuard::html(['spam_honeypot', 'spam_timer', 'spam_recaptcha']) !!}

    <!-- other form elements -->

</form>

2. 将 SpamGuard 中间件添加到您的路由或控制器

指定特定中间件

class MyController extends Controller
{
    public function __construct()
    {
        $this->middleware('spam_honeypot');
        $this->middleware('spam_timer');
        $this->middleware('spam_recaptcha');
    }
}

使用所有 spam 中间件

$this->middleware('spamguard');

通常在控制器中使用 spam_timer 中间件,并覆盖特定操作的 min_timemax_time

$this->middleware('spam_timer:10,300', ['only' => 'postComment']);

选项

目前注册了四个 spam 中间件

  • spam_honeypot
  • spam_timer
  • spam_recaptcha
  • spamguard:上述所有可用的 SpamGuard 中间件的集合。

注意

如果您选择性地使用元素和中间件,请注意您使用的元素必须与分配给路由的中间件相匹配。