PHPackages                             solophp/inertia - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. solophp/inertia

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

solophp/inertia
===============

PSR-7 and PSR-15 adapter for Inertia.js

v1.2.0(1y ago)1101MITPHPPHP &gt;=8.1

Since Jul 17Pushed 1y ago1 watchersCompare

[ Source](https://github.com/SoloPHP/Inertia)[ Packagist](https://packagist.org/packages/solophp/inertia)[ RSS](/packages/solophp-inertia/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (4)Versions (6)Used By (0)

Inertia PSR Adapter
===================

[](#inertia-psr-adapter)

[![Version](https://camo.githubusercontent.com/76a77d503967953c558d41fca7ab85c9230c376588808ba2a5c0dd3e01a821a5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f76657273696f6e2d312e322e302d626c75652e737667)](https://github.com/username/inertia-psr/releases)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![PHP Version](https://camo.githubusercontent.com/04744bae0a61d2ffe29c26f07a9612eae20445fc6feaeb77b3af1f0e9be6447c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e312d3838393242462e737667)](https://php.net/)

A PSR-7 and PSR-15 compatible adapter for Inertia.js, enabling seamless server-side integration with any PHP framework that implements these standards.

Features
--------

[](#features)

- Full PSR-7 HTTP message interface support
- PSR-15 middleware for handling Inertia-specific headers and responses
- Support for partial reloads and asset versioning
- Compatible with any PSR-7 compliant framework
- Proper handling of JSON and HTML responses based on request type
- Type-safe implementation with readonly properties
- Final classes for better predictability
- Shared props support across all pages

Installation
------------

[](#installation)

```
composer require solophp/inertia
```

Usage
-----

[](#usage)

### Basic Setup

[](#basic-setup)

1. First, configure the Inertia class with your root template and asset information:

```
use Solo\Inertia;

$inertia = new Inertia(
    rootTpl: '/path/to/root.php',
    assetsVersion: '1.0.0',
    js: '/dist/app.js',
    css: '/dist/app.css'
);
```

2. Add the InertiaMiddleware to your middleware stack:

```
use Solo\Inertia\InertiaMiddleware;

$middleware = new InertiaMiddleware($assetsVersion);
```

### Rendering Pages

[](#rendering-pages)

To render an Inertia page:

```
$response = $inertia->render(
    $request,
    $response,
    'Pages/Users/Index',
    [
        'users' => $users,
        'filters' => $filters
    ]
);
```

### Shared Properties

[](#shared-properties)

You can share data with all pages by setting the `sharedProps` request attribute:

```
$request = $request->withAttribute('sharedProps', [
    'auth' => [
        'user' => $currentUser,
    ],
    'flash' => [
        'message' => $flashMessage,
    ],
]);
```

These props will be automatically merged with page-specific props during rendering.

### Root Template Example

[](#root-template-example)

Create a root template (e.g., `root.php`):

```
DOCTYPE html>
