Conversation
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Table of Contents
Demo Applications
The following demo applications show Laravel Modules with Inertia in action:
Prerequisites — Installing Inertia
This guide assumes Inertia.js is already installed in your Laravel application. If it is not, run the following commands first.
1. Install the server-side adapter
2. Publish the Inertia middleware and add it to your stack
Then register it in
bootstrap/app.php(Laravel 11+):3. Install the client-side adapter for your framework
Vue
React
Svelte
4. Create the root Blade template
Inertia requires a single root
resources/views/app.blade.phpthat bootstraps every page. Create it if it does not already exist:Paste the following content:
@inertiaHead— renders the<title>and any<Head>tags set by your Inertia pages.@inertia— renders the root<div id="app">that Inertia mounts your frontend framework into.@vite(...)— injects the compiled JS (and CSS if you add it to the array). Point this at theapp.jspublished bymodule:publish-inertia.Configuration
A new top-level
inertiakey has been added toconfig/modules.php.This sets the default frontend framework used by all Inertia-related commands when no explicit
--vue,--react, or--svelteflag is passed. Set it once for your project and every command will pick it up automatically.Setting Up the Application Entry Point
The
module:publish-inertiacommand publishes a ready-maderesources/js/app.jsthat knows how to resolve pages from both your application and every module.Add
--forceto overwrite an existing file. The command readsconfig('modules.inertia.frontend')to pick the right template — or pass--vue,--react, or--svelteto override it for this one run.What the published file looks like
All three variants wrap
createInertiaAppin anif (el && el.dataset.page)guard so the app initialises only on pages that are actually served by Inertia — avoiding errors when the sameapp.jsis loaded on non-Inertia routes.Vue
React
Svelte
The key things in all three versions:
el && el.dataset.pageguard — Inertia setsdata-pageon the root<div>when rendering. The guard prevents the app from booting on non-Inertia pages.ModuleName/PageNameformat (e.g.Blog/Index). The resolver checks the module glob first and falls back to the app pages glob.Setting Up Your Application vite.config.js
Your application-level
vite.config.js(in the project root, not inside a module) needs the right plugin for your chosen framework. Add the plugin import and uncomment it in the plugins array:Vue
React
Svelte
Generating an Inertia Module
Command
What it generates
A standard web module minus the Blade views, plus Inertia-specific files:
app/Http/Controllers/<Name>Controller.phpresources/js/Pages/Index.{vue,jsx,svelte}resources/js/Pages/Create.{vue,jsx,svelte}resources/js/Pages/Show.{vue,jsx,svelte}resources/js/Pages/Edit.{vue,jsx,svelte}Blade files (
resources/views/index.blade.phpandresources/views/components/layouts/master.blade.php) are skipped.The controller stub (
controller-inertia.stub) returnsInertia::render()responses for each resource action, pre-wired to the module's page paths.Frontend selection
The pages are generated using the frontend set in
config/modules.php → inertia.frontend. There is no per-command override onmodule:make— configure the default in config before running.Example
Generating Inertia Pages
Command
Arguments & options
nameContacts/Indexmodule--vue--react--svelteconfig('modules.inertia.frontend')Output location
<ModulePath>/resources/js/Pages/<Name>.{vue,jsx,svelte}The path respects
config('modules.paths.generator.inertia.path')if customised.Examples
Stubs
src/Commands/stubs/inertia/page-vue.stubsrc/Commands/stubs/inertia/page-react.stubsrc/Commands/stubs/inertia/page-svelte.stub(new)Vue page stub — uses
<script setup>and@inertiajs/vue3<Head>.React page stub — named export with
@inertiajs/react<Head>.Svelte page stub — uses
<svelte:head>and importspagefrom@inertiajs/svelte.Generating Inertia Components
Arguments & options
nameUI/Buttonmodule--vue--react--svelteconfig('modules.inertia.frontend')Output location
<ModulePath>/resources/js/Components/<Name>.{vue,jsx,svelte}The path respects
config('modules.paths.generator.inertia-components.path')if customised.Examples
Stubs
src/Commands/stubs/inertia/component-vue.stub(new)src/Commands/stubs/inertia/component-react.stub(new)src/Commands/stubs/inertia/component-svelte.stub(new)Components are intentionally minimal — no
<Head>or Inertia-specific imports, just a plain component shell ready to build on.Config keys used
Both
pathvalues can be customised. Setgeneratetotrueif you want the directory created upfront when scaffolding a module.Vite Config Stub (Per-Module)
Each module has its own
vite.config.jsgenerated from a stub. This is separate from the application-levelvite.config.jscovered above — it handles the module's own assets (SCSS, JS) for independent builds.The per-module stub (
src/Commands/stubs/vite.stub) now includes commented-out entries for all three frameworks:Uncomment the relevant lines for whichever framework you are using.