Dealing with Form Spam in Laravel

If you have forms on your site -- contact form, registration form -- you will likely deal with robots generating form spam

You will need to deply technigues to deal with it.

Two techniques are

Honeypots

https://github.com/spatie/laravel-honeypot

 

composer require spatie/laravel-honeypot
php artisan vendor:publish --provider="Spatie\Honeypot\HoneypotServiceProvider" --tag=honeypot-config

Update routes/web.php and add the middleware to all POST routes for form action.

use App\Http\Controllers\ContactController;

use Spatie\Honeypot\ProtectAgainstSpam;

Route::get('contact', [ContactController::class, 'page'])->name('pages.contact');
Route::post('contact', [ContactController::class, 'send'])->middleware(ProtectAgainstSpam::class)->name('send.contact');

Add the honeypot blade directive to any form you need to protect

 

 

ReCAPTCHA