All posts

Laravel Rust won't compile until you say who can submit the form

Published December 2, 2026 · by Majd Ghithan, written with the help of AI

Laravel Rust won't compile until you say who can submit the form

I have reviewed a lot of Laravel pull requests where the Form Request looked like this: a careful rules() method, and an authorize() that just says return true;. Sometimes that is correct. Sometimes it is a hole that nobody noticed because nothing forced anyone to think about it.

Laravel Rust, which shipped its first beta on December 1, takes that decision out of "remember to do it" territory. If a handler validates a type that doesn't say who may submit it, the app does not compile. That one rule is the most interesting thing I found in its validation docs, so this post is about it.

The shape of an input struct

In Laravel Rust, you describe the incoming data as a struct. According to the docs, you "mark the struct with #[laravel::input(fills = Post)], which derives Deserialize and Validate for it and lets you save it to a Post. Then put each field's rules in a #[validate(...)] attribute".

Here is the example straight from the validation docs:

use laravel::prelude::*;

use crate::models::Post;

#[laravel::input(fills = Post)]
#[validate(anyone)]
pub struct StorePost {
    #[validate(required, max_length(255), unique(Post::title))]
    title: String,
    #[validate(required)]
    body: String,
}

And the handler that receives it:

use laravel::model::create;
use laravel::prelude::*;

use crate::models::Post;

pub async fn store(Valid(form): Valid<StorePost>) -> laravel::Result<Redirect> {
    let post = create!(Post { ..form }).await?;

    Ok(redirect!(show, post.id))
}

If you have written Form Requests, this reads naturally. The rules sit next to the fields instead of in an array of strings, and Valid<StorePost> in the handler signature plays the role that type-hinting a Form Request plays in a PHP controller.

Notice the line #[validate(anyone)] above the struct. That is the part that matters.

The rule: every input says who may submit it

The docs put it plainly: "Every type you validate from a request must say who may submit it. So a handler that validates a type without anyone, authenticated, or an authorize function doesn't compile."

You get these options:

  • #[validate(anyone)] for public forms, like a contact form or a signup.
  • #[validate(authenticated)] for anything that needs a logged-in user. A guest gets "a redirect to the login page, or a 401 for a request that expects JSON."
  • A policy check, for example #[validate(authorize(PostPolicy::update, route("post")))].
  • Or implement ValidatesRequest yourself with an authorize function.

When authorize returns false, "the request fails with a 403 and the message "This action is unauthorized.""

How this compares to Form Requests in PHP

In Laravel PHP, a Form Request has an authorize() method next to rules(). If it returns false, Laravel responds with a 403. That is a good design, and I have argued for Form Requests on this blog before.

The weak spot is not the feature, it is the habit. The stub that php artisan make:request creates returns false from authorize(), the first request fails, and the quickest fix is to flip it to true and move on. Also, nothing stops you from skipping Form Requests entirely and calling $request->validate() inside the controller, where there is no authorization step at all.

Laravel PHP: easy to wave through
public function authorize(): bool
{
    return true;
}
Laravel Rust: the choice is required
#[laravel::input(fills = Post)]
#[validate(anyone)]
pub struct StorePost {
    // ...
}

To be fair, #[validate(anyone)] is just as easy to type as return true;. The compiler can't judge whether "anyone" is right. What changes is that the decision is visible on the struct, it is a named choice instead of a default, and a reviewer can grep for anyone and ask "is this really public?" That is a better starting point for a code review than hunting through controllers for inline validation.

The other two safety details

Two more things in the docs are worth knowing.

Failed validation behaves like you'd expect from Laravel: "Laravel redirects the user back to the form", and an API client gets a JSON response listing the errors. The intro post says that response is a 422.

Mass assignment is handled by the struct itself: "Laravel ignores any submitted field that the struct doesn't declare, so a user can't add is_admin=1". In PHP you protect against that with $fillable or $guarded on the model, or by only passing validated data. Here the input struct is the allow list.

What I would watch for

Laravel Rust is beta. The docs say "Releases before 1.0 may include breaking changes to APIs and configuration," so the exact attribute syntax could change before 1.0. I would not memorize it yet. The principle, though, is the part worth stealing today.

Even if you never write a line of Rust, you can apply it to your PHP app: treat authorize() returning true as a decision that needs a reason in the PR, and keep validation in Form Requests rather than inline, so there is always one place where "who can do this" is answered.

My take

I like this a lot. On teams I have led, missing authorization was never a knowledge problem, it was an attention problem: people knew how to write a policy, they just did not get asked. Making the build fail until someone answers the question is the kind of guardrail I would want for a team of nine, not just for myself. It will not make your policies correct, but it removes the most common way they end up missing.

🤖 Heads up: this post was drafted with AI. Spot something wrong or off?Email me the correction →
Majd Ghithan

Majd Ghithan

Full-Stack Engineer & Tech Lead

More posts

Laravel in PracticeDec 2, 20266 min read

Laravel Go is here. What it is, how it differs from Laravel Rust, and where Goravel stands

On December 1, Laravel released the first beta of Laravel Rust. One day later, on December 2, Taylor Otwell published the first beta of Laravel Go. Two new official Laravel fram…

Laravel in PracticeDec 2, 20265 min read

The same Laravel ideas in three languages: PHP, Rust, and Go

The fastest way to understand a framework is to look at code you already know written in it. So instead of another feature list, this article puts the same Laravel concepts next…

Beyond the CodeDec 2, 20266 min read

Laravel PHP, Laravel Rust, or Goravel? Picking by fit, not by hype

As of December 2026 there are three ways to write an app with Laravel's ideas: the original in PHP, the new Laravel Rust beta, and Goravel in Go. They share a philosophy. They d…

Laravel in PracticeDec 2, 20265 min read

What is Goravel? Laravel's ideas, written in Go

Laravel Rust went into beta on December 1, 2026. It is the first time the Laravel team itself has taken the framework's conventions into a compiled language. It is not the first…

Beyond the CodeDec 2, 20264 min read

Laravel Rust is out. Should your team switch?

A week after the Laravel Rust beta landed on December 1, the question I keep getting is the same one: "Should we move our app to Rust?" For almost every team asking, my answer i…

Beyond the CodeDec 2, 20264 min read

Every new Laravel Rust app ships instructions for your AI agent

When I create a new Laravel project, one of the first things I do is add instructions for the coding agent: how this codebase is structured, which conventions to follow, which m…