Kritim Yantra
Jun 10, 2025
Imagine building a car:
Without Inertia? You’re manually wiring every button between frontend/backend. With it? You press "gas," and everything just works. Let’s explore why this trio is a game-changer!
Building React SPAs with Laravel usually means:
Inertia.js solves this by letting you use Laravel controllers directly in React!
Inertia.js isn’t a framework—it’s the glue between Laravel and React:
🧙 Analogy: Like ordering pizza through an app (React) that directly talks to the kitchen (Laravel), skipping the phone operator (API boilerplate).
// Laravel Controller (web.php)
Route::get('/dashboard', function () {
return Inertia::render('Dashboard', [
'user' => Auth::user() // Data sent DIRECTLY to React!
]);
});
// React Component (Dashboard.jsx)
export default function Dashboard({ user }) {
return <h1>Welcome, {user.name}!</h1>;
}
No API, no Axios calls, no reducers!
<Link>
component: import { Link } from '@inertiajs/react';
<Link href="/about">About Us</Link> // SPA-like navigation!
POST
handling: // Controller
public function update(User $user) {
$user->update(request()->all());
return back()->with('success', 'Profile updated!');
}
// React shows Laravel flash messages automatically!
{props.success && <p>{props.success}</p>}
laravel new inertia-app
cd inertia-app
composer require inertiajs/inertia-laravel
npm install @inertiajs/react react react-dom
resources/views/app.blade.php
: <!DOCTYPE html>
<html>
<head>
@vite('resources/js/app.js')
</head>
<body>
<div id="app" data-page="{{ json_encode($page) }}"></div>
</body>
</html>
// resources/js/app.js
import { createInertiaApp } from '@inertiajs/react';
import React from 'react';
createInertiaApp({
resolve: name => require(`./Pages/${name}`),
setup({ el, App, props }) {
ReactDOM.render(<App {...props} />, el);
},
});
php artisan make:controller UserController
// UserController.php
public function show() {
return Inertia::render('UserProfile', [
'posts' => Post::all()
]);
}
// resources/js/Pages/UserProfile.jsx
export default function UserProfile({ posts }) {
return posts.map(post => <div key={post.id}>{post.title}</div>);
}
Done! Visit /user
to see your React component powered by Laravel data. 🚀
<Form>
helper. npm run prod
+ php artisan optimize
).💬 Fun Fact: The creator of Laravel (Taylor Otwell) uses Inertia in his own projects!
Build a to-do app in 30 minutes using:
laravel new todo-app --jet --stack=inertia
(Jetstream sets up React + Inertia automatically!)
Drop a comment below with your experience! 👇
Stuck? Dive into the Inertia.js Docs!
No comments yet. Be the first to comment!
Please log in to post a comment:
Sign in with Google