| Install | |
|---|---|
composer require darvis/livewire-honeypot |
|
| Latest Version: | v1.0.3 |
| PHP: | ^8.2 |
Lightweight honeypot + time‑trap protection for Livewire 3 (Laravel 11).
Blocks simple bots without CAPTCHAs, privacy‑friendly and unobtrusive.
present|size:0)<x-honeypot /> for easy inclusioncomposer require darvis/livewire-honeypot
(For local development, you can add a path repository in your app's composer.json.)
use Darvis\LivewireHoneypot\Traits\HasHoneypot;
class ContactForm extends Component
{
use HasHoneypot;
public string $name = '';
public string $email = '';
public string $message = '';
public function submit(): void
{
$this->validate([
'name' => 'required|string|min:2',
'email' => 'required|email',
'message' => 'required|string|min:10',
]);
$this->validateHoneypot();
// process form ...
$this->reset(['name','email','message']);
$this->resetHoneypot();
}
}
<x-honeypot />
use Darvis\LivewireHoneypot\Services\HoneypotService;
public function store(Request $request, HoneypotService $honeypot)
{
$honeypot->validate($request->only('hp_website', 'hp_started_at', 'hp_token'));
// process form ...
}
To generate fields server‑side (non‑Livewire forms):
$hp = app(Darvis\LivewireHoneypot\Services\HoneypotService::class)->generate();
// pass $hp to your view to prefill hidden inputs
Publish the config file to customize settings:
php artisan vendor:publish --tag=livewire-honeypot-config
Available options in config/livewire-honeypot.php:
minimum_fill_seconds - Minimum time (in seconds) before form submission (default: 5)field_name - Name of the honeypot field (default: hp_website)token_min_length - Minimum token length for validation (default: 10)token_length - Length of generated token (default: 24)All settings can also be configured via environment variables:
HONEYPOT_MINIMUM_FILL_SECONDS=5
HONEYPOT_FIELD_NAME=hp_website
HONEYPOT_TOKEN_MIN_LENGTH=10
HONEYPOT_TOKEN_LENGTH=24
The package includes English and Dutch translations. Publish them to customize error messages:
php artisan vendor:publish --tag=livewire-honeypot-translations
Available translation keys in resources/lang/vendor/livewire-honeypot/{locale}/validation.php:
spam_detected - Error when honeypot field is filledsubmitted_too_quickly - Error when form is submitted too fasthoneypot_label - Label text for the honeypot fieldCustomize the honeypot component:
php artisan vendor:publish --tag=livewire-honeypot-views
Add request rate‑limiting on your form route:
Route::get('/contact', \App\Livewire\ContactForm::class)->middleware('throttle:10,1');
MIT © Arvid de Jong (info@arvid.nl)