PHPackages                             tuantq/laravel-prevent-spam - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. tuantq/laravel-prevent-spam

ActiveLibrary

tuantq/laravel-prevent-spam
===========================

Prevent spam with honeypot field

v1.0.0(6mo ago)17[3 issues](https://github.com/tqt97/laravel-prevent-spam/issues)MITPHP

Since Oct 25Pushed 6mo agoCompare

[ Source](https://github.com/tqt97/laravel-prevent-spam)[ Packagist](https://packagist.org/packages/tuantq/laravel-prevent-spam)[ RSS](/packages/tuantq-laravel-prevent-spam/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Laravel Prevent Spam 🛡️
=======================

[](#laravel-prevent-spam-️)

A lightweight Laravel package to protect your forms from spam bots using a **honeypot** and **timing protection**.
Simple to use, framework-native, and customizable.

---

🚀 Features
----------

[](#-features)

- 🧠 Invisible honeypot field to trap spam bots.
- ⏱️ Time-based protection: detects form submissions that are too fast.
- ⚙️ Fully configurable via `config/honeypot.php`.
- 💡 Blade component `` for easy integration.
- 🔒 Middleware-ready — just add it to any form processing route.
- 🧩 Easily override exceptions for custom responses.

---

🧩 Installation
--------------

[](#-installation)

Install the package via Composer:

```
composer require tuantq/laravel-prevent-spam
```

If you're using **Laravel 10+ or 11+**, package discovery will automatically register the service provider and config.

For older Laravel versions, register manually in `config/app.php`:

```
'providers' => [
    Tuantq\LaravelPreventSpam\PreventSpamServiceProvider::class,
],
```

---

⚙️ Publishing Configuration &amp; Views
---------------------------------------

[](#️-publishing-configuration--views)

After installation, you can publish the config and view files to customize them:

```
php artisan vendor:publish --provider="Tuantq\LaravelPreventSpam\PreventSpamServiceProvider" --tag=config
```

```
php artisan vendor:publish --provider="Tuantq\LaravelPreventSpam\PreventSpamServiceProvider" --tag=views
```

This will create a file at: `config/honeypot.php`This will copy the package view to: `resources/views/vendor/prevent-spam/honeypot.blade.php`You can then edit this file freely to match your form structure or CSS style.

---

🧱 Usage
-------

[](#-usage)

### 1️⃣ Add honeypot field to your form

[](#1️⃣-add-honeypot-field-to-your-form)

In your Blade form:

```

    @csrf

    Submit

```

This component automatically renders:

```

```

---

### 2️⃣ Protect your route or controller

[](#2️⃣-protect-your-route-or-controller)

Use the provided middleware to check the honeypot and timing:

```
use Tuantq\LaravelPreventSpam\Middleware\PreventSpam;

Route::post('/post/create', [PostController::class, 'store'])
    ->middleware(PreventSpam::class)
    ->name('posts.store');
```

---

### 3️⃣ Custom exception handling

[](#3️⃣-custom-exception-handling)

You can customize the spam handling logic globally or per middleware.

#### Option 1: Globally using Service Provider

[](#option-1-globally-using-service-provider)

```
// app/Providers/AppServiceProvider.php

use Tuantq\LaravelPreventSpam\Honeypot;

public function boot(): void
{
    Honeypot::abortUsing(function () {
        return response('Custom response for spam', 422);
    });
}
```

#### Option 2: Override in your own middleware

[](#option-2-override-in-your-own-middleware)

```
