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
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
ValidatesRequestyourself with anauthorizefunction.
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.
public function authorize(): bool
{
return true;
}
#[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.
