The beta’s handler style is the one in the routing guide: the route file names a function, and the function lives under src/http/handlers. Field Notes will follow that for notes. This lesson uses the User model the starter already has, because a note model does not exist yet. Binding works the same way once Note is a model.
Create src/http/handlers/users.rs and declare pub mod users; beside the other modules in src/http/handlers/mod.rs.
use laravel::prelude::*;
use crate::models::User;
pub async fn show(user: User) -> String {
user.name
}
Register it in src/routes/web.rs:
use crate::http::handlers::users;
route.get("/users/{user}", users::show);
The parameter name is the struct name in snake case: {user} for User, {blog_post} for BlogPost. A request to /users/1 loads that row and passes it in. If no row has that id, Laravel responds with 404 and does not run the rest of the handler. That is a missing record, not a validation error. You will meet 422 when a form struct rejects its body.
Seed a user only if migrate has not already given you one you can open. The authentication guide’s registration path uses create!, which hashes a Password for you. Until the sign-in lesson, it is enough to insert one row through a short closure you delete afterward, or through a user you create while trying the login form later. Do not invent a tinker command. The docs this series follows do not show a REPL.
What the handler is allowed to ask for
Extractors are the arguments. Order matters when a later lesson reads the body: Valid<T> has to be the last argument, because it consumes the body. A model parameter does not, so show(user: User) is fine on its own.
Returning user.name sends the name as the response body. Returning the whole User as JSON would also compile for a JSON response, but the models guide warns you about serialization: PasswordHash does not implement Serialize, and #[model] rejects it unless the field is #[serde(skip)]. The starter’s user is safe to load. It is not automatically safe to dump into a page. The pages course returns only the fields a screen needs.
A notes handler that does not pretend the table exists
Add src/http/handlers/notes.rs with an index that tells the truth about the current schema:
pub async fn index() -> &'static str {
"Field Notes has no table yet."
}
route.get("/notes", notes::index);
Leave {note} off until the model course. A binding to a type that is not a model will not follow the User example, and this series will not invent a second binding syntax to force it.
laravel route:list --path=users should show users::show. laravel route:list --path=notes should show notes::index. Request a user id you know exists, then one you know does not. Write down which status you got. The missing id is the 404 the routing guide describes.
Check your work
Request a real user id and a missing one. Only the missing id should be a 404.