solophp/inertia
| Install | |
|---|---|
composer require solophp/inertia |
|
| Latest Version: | v2.0.0 |
| PHP: | ^8.3 |
| License: | MIT |
| Last Updated: | Oct 28, 2026 |
| Links: | GitHub · Packagist |
Solo Inertia
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
- Installation
- Quick Start
- Upgrading from 1.x
- Responses and Root Template
- Shared Data and Partial Reloads
- Deferred, Merging and Once Props, Infinite Scroll
- Redirects, Validation and Precognition and Flash Data
- History Encryption, Asset Versioning and Server-Side Rendering
- Testing and the API Reference
License
MIT. See LICENSE.
Related Packages
Standalone Inertia.js v3 server-side protocol adapter for ProcessWire with Defer...
Starter application for SoloPHP with Inertia.js 3 and Svelte 5: server-side rout...
Version History
| Version | Released | PHP | License |
|---|---|---|---|
| v2.0.0 | ^8.3 | MIT | |
| v1.2.0 | >=8.1 | MIT | |
| v1.1.2 | >=7.4 | MIT | |
| v1.1.1 | >=7.4 | MIT | |
| v1.1.0 | >=7.4 | MIT | |
| v1.0.0 | >=7.4 | MIT |