Laravel for Rust Keeps the Names. Here Are 10 Places Where the Behaviour Changes
Models, Form Requests, queues, the scheduler: Laravel for Rust looks like the Laravel you know. I built a full app with it and clicked through every page. These are the ten places where a familiar name did something I didn't expect.
Laravel for Rust keeps Laravel's names wherever it can: create!, Post::query(), Form Requests, db::transaction, dispatch(), schedule, route(). That's why a Laravel developer is productive in it on day one. It's also where the surprises are. When a name is new, you read the docs. When a name is familiar, you assume, and the assumption is where the bug comes from.
Over the last week I built a complete blog with it: posts and tags, an admin, queues and mail, the scheduler, caching, htmx search, live comments over WebSockets, a durable workflow, an API, an Inertia dashboard and a Docker deploy. Every step was tested, and every page was also clicked through in a browser. The tests caught the obvious mistakes. The clicking found everything below.
All of it is checked on laravel-rust 0.1.4. The framework is in beta, so some of these may change, and I'll update this post when they do.
1. In a template, a model is just data
In Rust code, route!(posts::show, &post) gets a real Post, knows its route key is the slug, and builds /posts/hello-rust.
In a template, post isn't a Post any more. By the time the view renders, the handler's data has become plain values, a map of fields, and the template's route() can't see the model's route key. So it uses the map's id:
<a href="{{ route("posts::show", post) }}"> <!-- /posts/7 -->
The page renders, the link looks fine, and every click is a 404, because the route looks posts up by slug. A test that opens the page stays green.
What to do: in templates, pass the key yourself, route("posts::show", post.slug), and have one test that checks the link itself, not only the status code:
app.get("/").await.assert_ok().assert_see_html("/posts/hello-rust\"");
2. Route names in templates aren't checked
In Rust, posts::show in route! is the actual handler function. Rename it and the compiler points at every link that still uses the old name.
In a template, "posts::show" is a string. A typo compiles, the app starts, and the page returns 500 the first time someone opens it:
invalid operation: no route's handler is `posts::shw`: `route:list` lists them (./resources/views/posts/index.html:7)
The message is excellent: the bad name, the file, the line, and where to look. But you only see it when the page renders.
What to do: a test that opens every page. It's cheap, and it's the only thing that checks your templates.
3. There is no lazy loading, anywhere
In Eloquent, $post->tags quietly runs a query if the tags weren't loaded. Convenient, and the classic source of N+1.
Laravel for Rust has no lazy loading. In Rust code, reading a relationship you didn't load stops the program with the fix in the message:
Post::tags isn't loaded; add `.with(Post::tags)` to the query
Harsh, but you can't ship an N+1 by accident. Templates are subtler: an unloaded relationship is simply missing from the data. Not null, not an empty list. So {% if post.tags %} is false, the tag list doesn't render, and the page returns 200 without its tags. Loop over the tags without that if, and the same mistake becomes a 500.
What to do: when you add a relationship to a template, add .with(...) to the query in the same change. And test that the data is on the page, not only that the page loads.
4. The compiler checks required columns, until you add a hook
This one is a pleasant surprise at first. Forget a required column, and the code doesn't build:
error[E0080]: evaluation panicked: can't create a `User` without `email`
Then you add a creating hook to a model, for example one that builds the slug from the title. Now create!(Post { body: "..." }) compiles, and fails only at runtime. The framework can't know what the hook will fill in, so the check moves to right before the INSERT.
What to do: know that adding hooks costs you this guarantee for that model, and keep a test that creates one.
5. Queued jobs wait for the commit, by default
In PHP Laravel, dispatching a job inside a transaction is a classic bug: a fast worker picks the job up before the commit and doesn't find the row, or the transaction rolls back and the job still runs. The fix is afterCommit(), and you have to remember it.
Laravel for Rust does it for you. A job dispatched inside db::transaction is held until the commit, and dropped on a rollback:
db::transaction(async |_| {
NotifySubscribers { post_id: 1 }.dispatch().await?;
Err(laravel::abort(500))
})
.await;
// rolled back: 0 jobs pushed
The same goes for queued mail and events. This is a difference in your favour, and it's the reason the next one is easy to miss.
6. ...but your cache forget might not
After jobs that wait for the commit, it's natural to assume everything does. My first version flushed the blog's cache inside the same transaction that saved a post. Whether that's safe depends on where the cache lives:
| Cache store | forget inside a transaction |
|---|---|
database |
joins the transaction, waits for the commit |
memory |
happens at once, before the commit |
Redis will behave like memory: it's a separate server that knows nothing about your database transaction. With it, a visitor who comes in between the forget and the commit rebuilds the cache from the old data, and it stays stale for as long as the TTL. The same code is safe in development on the database store and racy in production the day someone moves the cache to Redis.
What to do: wrap side effects of a write in db::after_commit. It runs once the outermost transaction commits, drops the work on a rollback, and runs at once outside a transaction. PHP Laravel has the same tool, DB::afterCommit().
7. The scheduler is UTC only
There's no ->timezone('Europe/Kyiv') and no scheduler timezone setting: schedules run in UTC. A digest "every Monday at 09:00" goes out at 11:00 in Kyiv in winter and at 12:00 in summer.
When the local hour matters, schedule both candidate UTC hours and keep the one that's right:
schedule
.job(SendWeeklyDigest)
.weekly()
.mondays()
.twice_daily(6, 7)
.when(async || -> laravel::Result<bool> {
Ok(laravel::now().in_tz("Europe/Kyiv")?.hour() == 9)
})
.on_one_runner();
More code than ->timezone(), and honest about daylight saving time.
8. A validation redirect, followed by htmx, puts a whole page in your list
This one I'd never have found with tests. A comment form posts with htmx and appends the result to the comment list. Someone submits a name made of spaces: the browser's required lets it through, the server trims it and fails validation, and for a form in the web group that means a redirect back. htmx's request follows the redirect silently, gets the whole post page as a 200, and appends it to the comment list. Header, post, a second comment section, all inside the first one.
What to do: take the Request instead of Valid<T> and decide per request what a failed validation means. For htmx, render the form alone with its errors and a 422, and point htmx at the form with HX-Retarget and HX-Reswap. For a plain form post, let the framework redirect back as usual. htmx 2 doesn't swap 4xx responses by default, so one <meta name="htmx-config"> in the layout allows 422.
9. Without BROADCAST_CONNECTION, broadcasts vanish quietly
I added the REVERB_ lines to .env and missed the first one. The page connected to Reverb, the browser subscribed to the channel, the worker logged every event. Nothing ever arrived.
With BROADCAST_CONNECTION unset, the connection is discard, which drops every broadcast without a word.
What to do: set it to reverb, and restart both the server and the queue worker, since both read .env. When broadcasts don't arrive, BROADCAST_CONNECTION=log for a minute shows whether the problem is before Reverb or after it.
10. A POST to a missing page returns 419
$ curl -s -o /dev/null -w '%{http_code}\n' -X POST http://localhost:8000/no-such-page
419
The fallback route lives in the web group, which checks the CSRF token before the route runs. So a bot probing your site gets "Page Expired" for a page that never existed.
The Laravel team fixed this in the starter app on launch day by taking the CSRF check off the fallback route:
.without_middleware::<PreventRequestForgery>()
But laravel new downloads the starter app's latest release, which, when I started, came out before the fix. Check your src/routes/web.rs.
The pattern
Almost none of these are bugs in the framework. Most of them are the framework being stricter or more explicit than PHP Laravel, and a familiar name hiding that. Three habits caught them:
- Read the docs for the names you think you know, not only for the new ones. The docs are inside the crate for your exact version:
cargo doc -p laravel-rust --no-deps --open. - Test what's on the page, not just the status code. Links, tags, the data the user came for.
- Click through it. Tests check what you thought of. A browser checks what you didn't.
Laravel for Rust is a genuinely good framework, and most of the differences above are improvements once you know them. I wrote all of this up, with the full code and the fixes in context, in Laravel Rust in Practice. If you've hit a surprise that's not on this list, I'd like to hear about it.