The whole protocol
Inertia 3: the page object in a script element, partial reloads by path with only, except and reset, version conflicts, external and fragment redirects, error bags, flash data, history flags.
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.
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.']);
}
}composer require solophp/inertiaRequirements: 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.