Installing Inertia - React in Laravel Project
Let's learn how to install Inertia in a Laravel project with React

Search for a command to run...
Let's learn how to install Inertia in a Laravel project with React

No comments yet. Be the first to comment.
OpenClaw is a powerful, self-hosted AI assistant that connects to your tools to perform actions. Explore its Gateway architecture, real-world use cases, and security precautions.

Discover how neo-brutalism is shaping 2026 design trends. See how anti-design principles can create distinct, usable, and memorable product experiences.

When code breaks a pipeline, developers have to stop working and figure out why. This blog shows how an AI agent reads the error, finds the fix, and submits it for review all on its own.

GeekyAnts built a 5-agent fraud detection pipeline that makes decisions in under 200ms — 15x cheaper than single-model systems, with full explainability built in.

A deep dive into how GeekyAnts built a real-time AI fraud detection system that evaluates transactions in milliseconds using a hybrid multi-agent approach.

GeekyAnts Tech Blog
348 posts
GeekyAnts is an AI-powered digital product engineering and consulting company helping startups, enterprises, and Fortune 500 brands build scalable, future-ready digital solutions. Since 2006, we have delivered 800+ successful projects for 550+ global clients across healthcare, BFSI, retail, logistics, education, and enterprise technology. We help businesses accelerate digital transformation through strategy, design, engineering, and AI-led innovation.
Inertia ships with official server-side adapters for Laravel. In this article, we will install Inertia.js in Laravel with React.js.
First, we will perform server-side installation and then continue with the client-side installation.
Run the command below to install the Inertia package in your project via composer:
composer require inertiajs/inertia-laravel
Create a new file, app.blade.php in resources/views and paste the below code. This file will be loaded on the first page visit. This will be used to load your site assets (CSS and JavaScript), and will also contain a root <div> to boot your JavaScript application in.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale-1.0, maximum-scale=1.0" />
<link href="{{ mix('/css/app.css') }}" rel="stylesheet" />
<script src="{{ mix('/js/app.js') }}" defer></script>
</head>
<body>
@inertia
</body>
</html>
Next, set up the Inertia middleware. Run the below command to do the same. php artisan inertia:middleware
Once generated, register the HandleInertiaRequests middleware in your App\\Http\\Kernel, as the last item in your web middleware group.
'web' => [
// ...
\\App\\Http\\Middleware\\HandleInertiaRequests::class,
],
Now, our server-side installation is done.
Next, we will perform the client-side installation.
Install the Inertia client-side adapters using NPM or Yarn.
npm install @inertiajs/inertia @inertiajs/inertia-react
yarn add @inertiajs/inertia @inertiajs/inertia-react
Next, update your main JavaScript file app.js in resources/js/app.js. If you have existing app.js in that folder, rename the old file, create a new app.js, and write the below code in that file. What we're doing here is initializing the client-side framework with the base Inertia component.
import React from "react";
import { render } from "react-dom";
import { createinertiaApp } from "@inertiajs/inertia-react";
createInertiaApp({
resolve: name => import(`.Pages/${name}`),
setup({ el, App, props }) {
render(<App {...props} />, el);
}
});
Why do we need Babel? Code splitting breaks apart the various pages of your application into smaller bundles, which are then loaded on demand when visiting new pages. This can significantly reduce the size of the initial JavaScript bundle, improving the time first to render. To use code splitting with Inertia, you'll need to enable dynamic imports. That’s why you'll need a Babel plugin to make this work.
Run the below commands to install the babel plugins:
npm install @babel/plugin-syntax-dynamic-import
yarn add @babel/plugin-syntax-dynamic-import
Next, create a new file .babelrc in your project and add the following code.
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
Now, create a new Test.js component in resources/js/Pages for testing if our integration is successful.
import React from 'react';
import { Head } from '@inertiajs/inertia-react';
export default function Test() {
return (
<h1>Welcome</h1>
)
}
To render the component, make TestController and add a new route in web.php.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Inertia\Inertia;
class TestController extends Controller
{
public function show() {
return Inertia::render('Test');
}
}
Route::group([
"middleware" => ["auth"],
], function(){
Route::get('/test', 'TestController@show');
});
That’s it.
Try to call the route project_url/test, and your inertia with React in Laravel integration is done.
Hope you found this article helpful.