Skip to content

Middleware ​

InertiaMiddleware ​

Solo\Inertia\InertiaMiddleware — the protocol rules that apply to a whole response, whoever made it.

php
public function __construct(Inertia $inertia, ResponseFactoryInterface $responses)

For a request without X-Inertia, it only adds Vary: X-Inertia to the response. For an Inertia request:

WhenThen
A GET whose X-Inertia-Version is not $inertia->version409 with X-Inertia-Location (the request URL) and X-Inertia-Version, before any handler runs
A 302 after a PUT, PATCH or DELETEThe status becomes 303
A redirect whose Location has a #fragment, unless prefetchedA 409 with X-Inertia-Redirect instead of Location; other headers stay
AlwaysVary: X-Inertia, added once

It never adds X-Inertia: true: only render() marks a response as a page. List it before the middleware that turns exceptions into responses.

PrecognitionMiddleware ​

Solo\Inertia\PrecognitionMiddleware — answers the requests the client makes to validate a form while the user fills it in. See Precognition.

php
public function __construct(RequestValidatorInterface $validator, ResponseFactoryInterface $responses)
RequestResponse
Precognition: true, and the fields asked about in Precognition-Validate-Only are valid204 with Precognition: true and Precognition-Success: true; the handler does not run
Precognition: true, and some of those fields are invalid422 with Precognition: true and {"errors": {...}}, those fields' errors only; the handler does not run
Any otherThe handler's response

Every response varies by Precognition. Without Precognition-Validate-Only, every field counts; a field asked about brings its nested errors too, so address covers address.city.

RequestValidatorInterface ​

Solo\Inertia\Contracts\RequestValidatorInterface — validates a request the way its handler would, without running it.

php
/** @return array<string, mixed> field => message or messages; [] for a valid request */
public function errors(ServerRequestInterface $request): array;

The middleware runs after routing, so the request carries its route's attributes and parameters.

EncryptHistoryMiddleware ​

Solo\Inertia\EncryptHistoryMiddleware — sets the Inertia::ENCRYPT_HISTORY request attribute, so the pages rendered below it encrypt their history state, unless render() says encryptHistory: false. It has no dependencies. See History Encryption.

Released under the MIT License.