A clean, production-ready starter project demonstrating how to integrate Laravel as a REST API backend with React (Vite) as a frontend SPA.
This repository is the companion code for the blog post:
📖 Laravel + React: Complete Full-Stack Setup Guide with Benefits & Best Practices (2026)
| Layer | Technology |
|---|---|
| Backend | Laravel 11 |
| Authentication | Laravel Sanctum |
| Frontend | React 18 + Vite |
| HTTP Client | Axios |
| Routing | React Router DOM v6 |
| Styling | Tailwind CSS |
laravel-react-fullstack/
├── backend/ # Laravel REST API
│ ├── app/
│ │ ├── Http/
│ │ │ ├── Controllers/
│ │ │ │ ├── AuthController.php
│ │ │ │ └── PostController.php
│ │ │ └── Requests/
│ │ │ └── LoginRequest.php
│ ├── routes/
│ │ └── api.php
│ └── .env.example
└── frontend/ # React SPA
├── src/
│ ├── api/
│ │ └── axios.js
│ ├── components/
│ │ └── Navbar.jsx
│ ├── pages/
│ │ ├── Login.jsx
│ │ ├── Register.jsx
│ │ └── Dashboard.jsx
│ ├── App.jsx
│ └── main.jsx
├── index.html
└── vite.config.js
cd backend
# Install dependencies
composer install
# Copy env file
cp .env.example .env
# Generate app key
php artisan key:generate
# Configure your database in .env then run:
php artisan migrate
# Install Sanctum
php artisan install:api
# Start the server
php artisan serveLaravel API will run on: http://localhost:8000
cd frontend
# Install dependencies
npm install
# Start dev server
npm run devReact app will run on: http://localhost:5173
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /api/register |
Register new user | ❌ |
| POST | /api/login |
Login user | ❌ |
| POST | /api/logout |
Logout user | ✅ |
| GET | /api/user |
Get authenticated user | ✅ |
| GET | /api/posts |
List all posts | ✅ |
| POST | /api/posts |
Create a post | ✅ |
| GET | /api/posts/{id} |
Get single post | ✅ |
| PUT | /api/posts/{id} |
Update a post | ✅ |
| DELETE | /api/posts/{id} |
Delete a post | ✅ |
In config/cors.php:
'supports_credentials' => true,
'allowed_origins' => ['http://localhost:5173'],Want to understand how every piece of this setup works?
👉 Read the full guide here: https://usmannadeem.com/laravel-react-full-stack-setup/
The blog post covers:
- Why Laravel + React is a powerful full-stack combination
- Laravel REST API vs Inertia.js — which to choose
- Step-by-step setup walkthrough
- Authentication with Laravel Sanctum
- Best practices from real client projects
- A real-world case study
Usman Nadeem — Freelance Full-Stack Developer
- 🌐 Portfolio: usmannadeem.com
- 📖 Blog: usmannadeem.com/laravel-react-full-stack-setup/
MIT License — free to use for personal and commercial projects.