solophp / inertia
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
Requires
- php: ^8.3
- psr/http-factory: ^1.1
- psr/http-message: ^2.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
- psr/log: ^3.0
Requires (Dev)
- nyholm/psr7: ^1.8
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.3
- psr/http-client: ^1.0
- squizlabs/php_codesniffer: ^3.13
Suggests
- psr/http-client: For server-side rendering with Ssr\HttpGateway, with any PSR-18 client
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-28 19:48:37 UTC
README
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.