PHP code example of devlop / honeypot

1. Go to this page and download the library: Download devlop/honeypot library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

devlop / honeypot example snippets


namespace App\Http\Requests;

use Devlop\Honeypot\WithHoneypot;
use Illuminate\Foundation\Http\FormRequest;

class DemoRequest extends FormRequest
{
    use WithHoneypot;

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules() : array
    {
        return $this->withHoneypotRules([
            // your normal rules goes here
        ]);
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules() : array
    {
        return [
            // your normal rules goes here,
            $this->getHoneypotInputName() => $this->honeypotRules(),
        ];
    }

namespace App\Http\Controllers;

use App\Requests\DemoRequest;
use Illuminate\Http\Request;

class DemoController
{
    public function store(DemoRequest $request)
    {
        // get the honeypot
        $honeypot = $request->honeypot();

        if ($honeypot->triggered()) {
            // do something when the honeypot was triggered
        }
    }
}

php artisan vendor:publish --provider="Devlop\Honeypot\HoneypotServiceProvider"
html
<form method="POST" action="/">
    <x-honeypot />

    ... all your other form contents
</form>