Building Modern Web Applications with the Laravel React Starter Kit
Overview of the New Laravel Ecosystem
Prerequisites and Tooling
To follow this guide, you should have a solid grasp of
- PHP 8.2+ and Composer
- Node.js and NPM
- Laravel Installer: The easiest way to scaffold new projects.
- Laravel Herd: Recommended for a seamless local development environment, including built-in mail trapping.
Key Libraries & Tools
- Inertia.js: The essential bridge that connects server-side routing with client-side components.
- Tailwind CSS: The latest utility-first CSS framework for rapid UI development.
- ShadCN UI: A collection of re-usable components that you copy and paste into your apps.
- Vite: The lightning-fast build tool for modern frontend development.
Code Walkthrough: Installation and Layouts
You can initiate a project using the
laravel new my-app --starter=react
Once installed, you can modify the application's look by swapping layouts. Unlike previous iterations, the Simple, Card, and Split for authentication, and Sidebar or Header for the main dashboard.
// resources/js/layouts/AppLayout.tsx
import { AppSidebarLayout } from '@/components/app-sidebar-layout';
// Switch to AppHeaderLayout to move navigation to the top
Customizing the App Sidebar
The sidebar is highly configurable. By adjusting the variant and collapsible props in the AppSidebar component, you can change the UI from a standard sidebar to a floating menu or an off-canvas overlay.
<Sidebar
variant="floating"
collapsible="icon"
>
{/* Navigation items */}
</Sidebar>
Syntax Notes and Best Practices
tailwind.config.js by default, moving configuration directly into your app.css. Use CSS variables to define theme overrides like fonts or custom colors. When adding components via
Tips & Gotchas
- Email Verification: To enforce verification, implement the
MustVerifyEmailinterface on yourUsermodel and add theverifiedmiddleware to your routes. - Database: The kit defaults to SQLite, which is perfect for local prototyping but requires migration toMySQLorPostgreSQLfor production.
- Environment: Always update your
.envfile with local mail settings fromLaravel Herdto test password resets and verification flows effectively.
