Skip to content

Commit

Permalink
Merge pull request #125 from jcsoriano/readme-for-volt
Browse files Browse the repository at this point in the history
Add instructions on how to use with Volt functional syntax
  • Loading branch information
freekmurze authored Dec 1, 2023
2 parents fb61540 + a40306e commit 6e80d2a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,31 @@ Finally, use the `x-honeypot` in your Livewire Blade component:
</form>
```

#### Usage in Volt functional syntax

To use this package in Volt functional syntax, return the `HoneypotData` property from the `guessHoneypotDataProperty` method.

```php
uses(UsesSpamProtection::class);

state([
// ...
'extraFields' => null,
]);

mount(function () {
$this->extraFields = new HoneypotData();
});

$guessHoneypotDataProperty = fn () => $this->extraFields;

$submit = function () {
$this->protectAgainstSpam(); // if is spam, will abort the request

User::create($request->all());
};
```

### Disabling in testing

By default, any protected form that is submitted in faster than 1 second will be marked as spammy. When running end to end tests, which should run as fast as possible, you probably don't want this.
Expand Down

0 comments on commit 6e80d2a

Please sign in to comment.