Skip to content

musman92/larave-react-starter-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Laravel + React Full-Stack Setup (2026)

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)


🚀 Tech Stack

Layer Technology
Backend Laravel 11
Authentication Laravel Sanctum
Frontend React 18 + Vite
HTTP Client Axios
Routing React Router DOM v6
Styling Tailwind CSS

📁 Project Structure

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

⚙️ Backend Setup (Laravel)

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 serve

Laravel API will run on: http://localhost:8000


⚙️ Frontend Setup (React)

cd frontend

# Install dependencies
npm install

# Start dev server
npm run dev

React app will run on: http://localhost:5173


🔐 API Endpoints

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

🌐 CORS Configuration

In config/cors.php:

'supports_credentials' => true,
'allowed_origins' => ['http://localhost:5173'],

📖 Full Blog Post

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

👨‍💻 Author

Usman Nadeem — Freelance Full-Stack Developer


📄 License

MIT License — free to use for personal and commercial projects.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors