Skip to content

Solo InertiaInertia.js 3 for PSR-7 and PSR-15

Server-driven single-page apps with any PSR framework โ€” pages, partial reloads, deferred, merge and once props, flash data, history encryption and server-side rendering.

Solo Inertia

Quick Example โ€‹

php
use Solo\Inertia\Inertia;

final readonly class TaskController
{
    public function __construct(private Inertia $inertia, private TaskRepository $tasks)
    {
    }

    public function index(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
    {
        return $this->inertia->render($request, $response, 'Tasks/Index', [
            'tasks' => fn() => $this->tasks->all(),                 // called only when sent
            'stats' => Inertia::defer(fn() => $this->tasks->stats()), // loaded right after the page
        ]);
    }

    public function store(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
    {
        $title = trim((string) ($request->getParsedBody()['title'] ?? ''));
        if ($title === '') {
            return $this->inertia->back($request, $response, errors: ['title' => 'The title is required.']);
        }

        $this->tasks->create($title);

        return $this->inertia->redirect($request, $response, '/tasks', flash: ['success' => 'Task created.']);
    }
}

Installation โ€‹

bash
composer require solophp/inertia

Requirements: PHP 8.3+, a PSR-7 and PSR-17 implementation, and an Inertia.js 3 client โ€” @inertiajs/svelte, @inertiajs/vue3 or @inertiajs/react. The Svelte skeleton is a complete application to start from.

Released under the MIT License.