Installation | laravel-honeypot-rust | Spatie       

 SPATIE  

laravel-honeypot-rust
=====================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-honeypot-rust](https://spatie.be/docs/laravel-honeypot-rust/v1)  Installation

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-honeypot-rust/v1) 

  Installation    
- [ Introduction ](https://spatie.be/docs/laravel-honeypot-rust/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-honeypot-rust/v1/support-us)
- [ Installation ](https://spatie.be/docs/laravel-honeypot-rust/v1/installation-and-setup)
- [ Usage ](https://spatie.be/docs/laravel-honeypot-rust/v1/usage)
- [ Testing ](https://spatie.be/docs/laravel-honeypot-rust/v1/testing)
- [ Changelog ](https://spatie.be/docs/laravel-honeypot-rust/v1/changelog)

 Installation
============

###  On this page 

1. [ Install the package ](#content-install-the-package)
2. [ Configure the application ](#content-configure-the-application)

Install the package
-----------------------------------------------------------------------------------------------------------------

1. Install Rust 1.99 or newer using [rustup](https://rustup.rs/). The repository pins 1.99.0 in `rust-toolchain.toml`.
2. Add a local path dependency. This package has `publish = false` and is distributed through GitHub, not crates.io:

```
[dependencies]
spatie-laravel-honeypot = { path = "../laravel-honeypot-rust" }
```

For a Git dependency, use `https://github.com/spatie/laravel-honeypot-rust` and pin `rev` to a tested full commit ID. The repository is public; no GitHub token is needed to fetch it. Keep `Cargo.lock` committed.

The runtime dependencies are `laravel-rust =0.1.0` with MiniJinja enabled and a pinned public Git revision of `spatie-laravel-package-tools`. No framework substitutes or local patches are needed.

Configure the application
-----------------------------------------------------------------------------------------------------------------------------------

1. Register the package-tools provider to load environment settings and bind a shared `Honeypot`:

```
use laravel::{Application, container::Inject, http::Json};
use spatie_honeypot::{Honeypot, service_provider};

let app = Application::configure()
    .with_providers(|providers| {
        providers.add(service_provider());
    })
    .with_config(|config, _| {
        config.section_mut::<spatie_honeypot::Config>().scope = "contact".into();
    })
    .with_routing(|routing, _| {
        routing.web(|route| {
            route.get("/contact/fields", async |honeypot: Inject<Honeypot>| {
                Ok::<_, laravel::Error>(Json(honeypot.fields()?))
            });
        });
    })
    .create();
```

2. Keep the application key and previous keys consistent across instances. The provider uses `Encrypter::from_config(&config.app)` when the singleton is first resolved. Invalid keys or honeypot settings return native resolution errors with their typed causes. To construct a separate per-form instance, use `Honeypot::new(encrypter).configure(settings)?`.
3. Attach middleware to POST routes accepting forms or JSON and register the template helper as shown in [usage](usage). Leave session and CSRF middleware in place. Use a different scope for each independent form purpose.

- Application config callbacks run after package defaults, so they can override any option. Application service bindings can replace the singleton.
- Registering the provider alone does not read an encryption key, render fields, or protect routes. The service is lazy; `Application::resolve` panics on resolution errors, while `laravel::resolve` returns a `Result` inside an application scope.
- The provider does not register a global template helper. Explicit `honeypot.register(environment)` keeps the helper's scope and middleware settings in sync.
- Existing per-form setup remains supported without the provider. Imports remain `spatie_honeypot`.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
