|
| 1 | +# Grease & Inertia |
| 2 | + |
| 3 | +## On the server, an Inertia visit *is* an API request — Grease greases it the same way |
| 4 | + |
| 5 | +[Inertia](https://inertiajs.com) moves rendering to Vue/React on the client, but the server |
| 6 | +half never changes shape. A controller queries its models, serializes them into props, and |
| 7 | +returns JSON: |
| 8 | + |
| 9 | +```php |
| 10 | +return Inertia::render('Users/Index', [ |
| 11 | + 'users' => User::with('posts')->get(), |
| 12 | +]); |
| 13 | +``` |
| 14 | + |
| 15 | +On the PHP side that's query → hydrate → serialize → respond — the exact path the |
| 16 | +[benchmarks](/guide/benchmarks) and `realworld.php` already measure on a plain JSON endpoint. |
| 17 | +Every visit is a fresh request; there's no persistent server-side component state. So the tiers |
| 18 | +land precisely as they do on an API route: |
| 19 | + |
| 20 | +- **Model hydration / casting** — the controller queries the models behind the props. |
| 21 | +- **`toArray()` + date serialization** — Inertia serializes props to JSON through the same path, |
| 22 | + so a model or resource prop runs the [date/cast tiers](/guide/serialization-helpers). |
| 23 | +- **Container / request / router / events** — the request envelope, greased like any route. |
| 24 | + |
| 25 | +There's nothing Inertia-specific to install or configure: the model + serialization tiers are |
| 26 | +your props, the foundation tiers are the request. Add `HasGrease` to the models your controllers |
| 27 | +return and the existing [API numbers](/guide/benchmarks) are your numbers. |
| 28 | + |
| 29 | +## The easy case — no snapshot, no checksum |
| 30 | + |
| 31 | +Where [Livewire](/guide/livewire) ships a checksummed snapshot of model state between requests — |
| 32 | +a real place a one-byte serialization drift could break rehydration — Inertia carries no such |
| 33 | +thing. Props are plain JSON in the response, regenerated from scratch every visit; nothing is |
| 34 | +HMAC-sealed, no state round-trips through the browser. So there's no byte-identity subtlety to |
| 35 | +reason about beyond Grease's standing promise that serialized output is |
| 36 | +[byte-identical to vanilla](/guide/why#the-one-rule-byte-identical-output) — which every tier |
| 37 | +already keeps. Partial reloads (`only`/`except`) just send a subset of those same props: still a |
| 38 | +fresh request, fewer props serialized. |
| 39 | + |
| 40 | +(Inertia's SSR renders Vue/React in a Node process — Grease is a PHP package and doesn't touch |
| 41 | +it. The PHP side still only produces the props JSON, and that's what gets greased.) |
| 42 | + |
| 43 | +## Getting started |
| 44 | + |
| 45 | +Add `HasGrease` to the [Eloquent models](/guide/getting-started) your controllers pass as props — |
| 46 | +that's the whole story. The [Blade component tier](/guide/blade) barely applies (Inertia's only |
| 47 | +Blade is the root `app.blade.php` rendered once on the first load; every visit after is JSON), but |
| 48 | +the [container](/guide/container), [request](/guide/request), [router](/guide/routing), and |
| 49 | +[event](/guide/events) tiers all apply to the request like any other route and compound on top. An |
| 50 | +Inertia app is an API app wearing a SPA — greasing it is the same work, in the same place. |
0 commit comments