fidelo-software / laravel-spamshield
Simple spam detection
v2.2.0
2025-02-27 14:15 UTC
Requires
- php: ^8.0
- illuminate/http: ^9.0|^10.0|^11.0|^12.0
- illuminate/support: ^9.0|^10.0|^11.0|^12.0
Requires (Dev)
- mockery/mockery: 1.6.*
- pestphp/pest: ^3.0
README
Installation
Install the package via composer
composer require fidelo-software/laravel-spamshield
Basic usage
Generate spamshield instance with strategies you want to use
$spamshield = new \FideloSoftware\Spam\SpamShield( [ new \FideloSoftware\Spam\Strategies\HoneypotStrategy(3), new \FideloSoftware\Spam\Strategies\TimestampStrategy($store, 5), new \FideloSoftware\Spam\Strategies\LinkStrategy(0), new \FideloSoftware\Spam\Strategies\ValueBlacklistStrategy(['name' => ['John Doe']]), ], $store $logger // optional );
Start all strategies onload processes when form is initializing
// Form initialization $spamshield->onload($form, $request);
Include all html parts of defined strategies in your form rendering process
// Form rendering echo $spamshield->html($form);
Execute all strategies on form submit to check for spam
// Submit try { $spamshield->detect($form, $request); } catch(\FideloSoftware\Spam\Exceptions\BannedException $e) { ... } catch(\FideloSoftware\Spam\Exceptions\SpamDetectionException $e) { ... }
Check user request globally
// Check if user is globally banned after to many attempts \FideloSoftware\Spam\SpamShield::isBanned($store, $request);