Search by

solophp / inertia

Vitaliy Olos

Inertia.js 3 server adapter for PSR-7 and PSR-15: pages, partial reloads, deferred, merge and once props, flash data, history encryption and server-side rendering

v2.0.0 2026-10-28 18:48 UTC

This package is auto-updated.

Last update: 2026-10-28 19:48:37 UTC


README

Latest Version on Packagist PHP Version License

An Inertia.js 3 server adapter for PSR-7 and PSR-15: build a single-page app with Svelte, Vue or React and server-side routing and controllers, in any PSR framework. It implements the whole protocol: partial reloads, deferred, optional, always, merge, once and infinite scroll props, version conflicts, external and fragment redirects, validation errors and error bags, flash data, history encryption, Precognition and server-side rendering.

Upgrading from 1.x? Read the upgrade guide. 2.0 speaks the Inertia 3 protocol and needs an Inertia 3 client.

Installation

composer require solophp/inertia

Requires PHP 8.3+, a PSR-7 implementation with PSR-17 factories, and an Inertia.js 3 client such as @inertiajs/svelte.

Example

use Solo\Inertia\CookieFlashStore;
use Solo\Inertia\Inertia;
use Solo\Inertia\PhpRootView;

$inertia = new Inertia(
    new PhpRootView(__DIR__ . '/resources/views/app.php'),
    version: $assetVersion,
    flash: new CookieFlashStore($appKey),
);

// A handler: the HTML document on a first visit, the page object as JSON afterwards
return $inertia->render($request, $response, 'Tasks/Index', [
    'tasks' => fn() => $tasks->all(),                 // called only when sent
    'stats' => Inertia::defer(fn() => $tasks->stats()), // loaded right after the page
]);

// After a form: errors back to it, or a redirect with a message
return $inertia->back($request, $response, errors: ['title' => 'The title is required.']);
return $inertia->redirect($request, $response, '/tasks', flash: ['success' => 'Task created.']);

InertiaMiddleware handles stale assets (a 409 before any handler runs), turns a 302 after PUT, PATCH or DELETE into a 303, and makes redirects with a fragment reach the client. Shared props come from any middleware: $handler->handle(Inertia::share($request, ['auth.user' => fn() => $user])).

The Svelte skeleton is a complete application built with it.

Documentation

Full Documentation

License

MIT. See LICENSE.