Custom validation rules have no documented way to reach the request

Open
#848 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@ruttydm is already working on this.

Since Dec 4, 2026.

  • #877 by @ruttydm — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
35/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Stale
Tech stack
rust

Research direction

Start with laravel-rust-http-0.2.0/src/validation/mod.rs around line 846 and the validation guide. Check the open pull request #877 to see how the work is progressing and whether the intended API is settled. Done means documenting Field::request, including request context and the error when validation runs outside a request.

Written by the indexing model from the issue text.

Description

A custom ValidationRule sometimes needs the request: its session, the client IP, or the logged-in user. Field::request(&self, rule: &str) -> Result<&Request> exists and works with Valid and request.validate(), but it is #[doc(hidden)], so packages can't rely on it staying public. The documented alternative is building the rule inside ValidatesRequest::rules, which receives &Request, but that doesn't work for a rule used inside #[validate(...)] attributes.

Example: a rule that checks a submitted answer against a value stored for the visitor's session:

impl ValidationRule for SessionAnswer {
    async fn validate(&self, field: &Field<'_>) -> Result<(), RuleError> {
        let request = field.request("session_answer")?; // hidden API today
        let session = request.session()?;
        // compare field.value with what the session expects
        Ok(())
    }
}

Suggestion

Make Field::request part of the documented API, with a short section in the validation guide on rules that need the request (session, IP, user), and on the error a rule gets when it's validated outside a request.

Seen on 0.2.0 (laravel-rust-http-0.2.0/src/validation/mod.rs:846); the same on 0.x at 6156f0e. I'm happy to send a docs PR if this is the intended API.

Dominant language
Rust
Stars
847
Forks
174
Avg merge
5h 40m
Merged PRs (30d)
167

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from laravel/rust-framework

All issues in laravel/rust-framework

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.