1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//! 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.
use TokenStream;
use ;
/// `#[derive(FormRequest)]`: generates an `axum::extract::FromRequest` impl
/// 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's `FormRequest`).
///
/// ```ignore
/// #[derive(FormRequest)]
/// pub struct StorePostRequest {
/// #[validate(required, length(max = 255))]
/// pub title: String,
/// }
/// ```
/// `view!("posts.index", { posts })`: reads, parses, and resolves
/// `resources/views/posts/index.blade.xr` (including any `@extends` layout
/// chain) at compile time, and generates code that renders it into a
/// `View`. 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 genuine `rustc` compile error, not a
/// custom check.
///
/// ```ignore
/// view!("posts.index", { posts })
/// ```
/// `error_view!("404")`: compiles `resources/views/errors/404.blade.xr` if
/// the app defines one, else Larust's own built-in default page for that
/// status - always produces a `String`. See `error_view.rs`'s own doc
/// comment for the override mechanism's limitations (no context bindings,
/// so no `@wire`/`@can`/`@role`/`persist` globals, and best kept
/// self-contained rather than `@extends`-ing a session-aware layout).
///
/// ```ignore
/// error_view!("404")
/// ```
/// `#[derive(Model)]`: generates `TABLE`/field-name constants, `query()`,
/// `all()`, `find(id)`, `create(data)`, and `delete(id)` over
/// `larust-orm`'s `QueryBuilder`, plus route model binding - an
/// `axum::extract::FromRequestParts` impl so a handler can declare
/// `post: Post` on 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 be `i64`).
/// `#[route_key("slug")]` looks records up by that field instead of the
/// primary key. `#[timestamps]` (Laravel's `$table->timestamps()`) opts
/// into automatic `created_at`/`updated_at` population - both must exist
/// as `i64` (Unix seconds) fields; `create()` stamps both, `update()`
/// re-stamps `updated_at` only, and neither appears in the generated
/// `New*` struct, matching Eloquent's own "never set these yourself"
/// behavior.
///
/// `#[soft_deletes]` (Laravel's `SoftDeletes` trait) opts into a nullable
/// `deleted_at: Option<i64>` field: `delete()` sets it instead of
/// removing the row, every `query()`/`find()`/`all()`/route-model-binding
/// lookup transparently excludes trashed rows (`QueryBuilder::{
/// with_trashed, only_trashed}` opt back in), and `force_delete`/
/// `restore`/`find_with_trashed`/`.trashed()` round out the rest.
///
/// `#[observe(creating = ..., created = ..., updating = ..., updated = ...,
/// deleting = ..., deleted = ...)]` (Laravel's model-event observers) runs a
/// plain function around `create`/`update`/`delete` - `creating`/`updating`
/// transform (or veto, by returning `Err`) the data before the write;
/// `created`/`updated`/`deleted` run after, with the result; `deleting`
/// runs before, with the row fetched fresh for the purpose. Fixed hook
/// signatures, checked by `rustc` at the generated call site - a
/// mismatch is a compile error pointing at the attribute itself, not a
/// trait-impl error several layers removed from it.
///
/// `#[has_many(...)]`/`#[has_one(...)]`/`#[belongs_to(...)]` (repeatable)
/// generate Laravel-style relationship accessor methods, both a lazy
/// per-instance form and a batch/eager `load_*` form; `#[belongs_to_many(
/// ...)]` (repeatable) generates a many-to-many relationship through a
/// pivot table (`tags()`/`attach_*`/`detach_*`/`sync_*`, no eager-loading
/// form yet); `#[has_many_through(...)]` (repeatable) generates a 3-table
/// relationship (Laravel's `hasManyThrough`) as a composable
/// `{method}_query()` plus a `{method}()` convenience wrapper, built on
/// `QueryBuilder::where_in_query` rather than a real `JOIN` (also no
/// eager-loading form yet) - see `docs/MACROS.md` for the full grammar
/// and generated shapes.
///
/// ```ignore
/// #[derive(Model, sqlx::FromRow)]
/// #[table("posts")]
/// #[belongs_to(User, foreign_key = "user_id")]
/// #[belongs_to_many(Tag, through = "post_tag", foreign_key = "post_id", related_pivot_key = "tag_id")]
/// pub struct Post {
/// #[primary_key]
/// pub id: i64,
/// pub user_id: i64,
/// pub title: String,
/// }
/// ```