atendwa/laravel-honeypot

This Laravel package safeguards your forms effortlessly with an invisible shield against spam, featuring seamless integration and configurable settings for optimal protection.

1.1.2 2024-05-17 09:15 UTC

This package is auto-updated.

Last update: 2024-11-08 10:26:37 UTC


README

Latest Version on Packagist Software License

run-tests Quality Score Code Style Status

Laravel Honeypot is a package designed to help protect your Laravel applications from spam bots by adding a hidden form field that, when filled, indicates the submission is likely from a bot. It provides a simple and effective method to reduce spam submissions without inconveniencing genuine users.

Installation

You can install the package via composer:

composer require atendwa/laravel-honeypot

Configuration

You can override the default options for the honeypot. First publish the honeypot.php configuration file:

  php artisan vendor:publish --provider="Atendwa\Honeypot\HoneypotServiceProvider" --tag="config"

Add the following variables in your .env file to use you custom configurations

HONEYPOT_ENABLED=TRUE

HONEYPOT_INPUT_NAME=mobile

HONEYPOT_TIME_INPUT_NAME=time_field

HONEYPOT_MINIMUM_SUBMISSION_DURATION=1 #time in seconds

Usage

  1. Add the prevent-spam middleware to the routes you want to protect from spam bots.

    Route::post('/submit-comment', [commentController::class, 'store'])
        ->middleware('prevent-spam');
  2. Add the <x-honeypot::honeypot-fields/> blade component to the form body

    <form action="/submit-comment" method="POST">
        @csrf
    
        <x-honeypot::honeypot-fields/>
        
        // other input fields
    </form>

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email tendwa.am@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.