Expand description
Procedural macros for Larust. #[controller] lands once it has real
payload (M6) - see rust-laravel.md’s milestone plan for why it wasn’t
built speculatively.
Macros§
- error_
view error_view!("404"): compilesresources/views/errors/404.blade.xrif the app defines one, else Larust’s own built-in default page for that status - always produces aString. Seeerror_view.rs’s own doc comment for the override mechanism’s limitations (no context bindings, so no@wire/@can/@role/persistglobals, and best kept self-contained rather than@extends-ing a session-aware layout).- view
view!("posts.index", { posts }): reads, parses, and resolvesresources/views/posts/index.blade.xr(including any@extendslayout chain) at compile time, and generates code that renders it into aView. Interpolated expressions ({{ user.name }}) and directive conditions/iterables (@if(...),@foreach(...)) are parsed as real Rust expressions and spliced directly into the generated function body - an undeclared variable is a genuinerustccompile error, not a custom check.
Derive Macros§
- Form
Request #[derive(FormRequest)]: generates anaxum::extract::FromRequestimpl that validates a form-urlencoded body against each field’s#[validate(...)]rules before the handler runs, returning a 422 with Laravel-shaped field errors on failure (Laravel’sFormRequest).- Model
#[derive(Model)]: generatesTABLE/field-name constants,query(),all(),find(id),create(data), anddelete(id)overlarust-orm’sQueryBuilder, plus route model binding - anaxum::extract::FromRequestPartsimpl so a handler can declarepost: Poston a route like/posts/{post}and have it auto-resolved (404 if not found). Requires#[table("...")]on the struct and exactly one#[primary_key]field (currently must bei64).#[route_key("slug")]looks records up by that field instead of the primary key.#[timestamps](Laravel’s$table->timestamps()) opts into automaticcreated_at/updated_atpopulation - both must exist asi64(Unix seconds) fields;create()stamps both,update()re-stampsupdated_atonly, and neither appears in the generatedNew*struct, matching Eloquent’s own “never set these yourself” behavior.