How To Add Nexts.js to Laravel

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

How To Integrate Next.js with Laravel: A Developer's Guide to Decoupled Architecture

As a senior developer, I often see developers looking to combine the robustness of a backend framework like Laravel with the modern, powerful capabilities of a frontend framework like Next.js. The desire to use both is understandable—you get a structured API, excellent Eloquent ORM, and a blazing-fast React/Next.js experience on the client side.

However, when asking how to add Next.js directly into Laravel via a simple preset, we need to address an important architectural distinction. Unlike presets for Blade or Livewire, there isn't a single command that magically stitches a full Next.js application into your existing Laravel structure in the same way. The cleanest and most scalable approach is to treat Laravel and Next.js as two distinct but tightly integrated services.

This guide will walk you through the recommended method—the decoupled architecture—and how to establish seamless communication between them, ensuring your project remains clean, correct, and maintainable.

Understanding the Separation of Concerns

The core philosophy here is separation of concerns. Laravel should act purely as a robust API provider (handling authentication, database interactions, and business logic), while Next.js serves purely as the presentation layer. Trying to embed Next.js components directly into Blade views often leads to messy code, poor performance isolation, and maintenance headaches down the line.

Therefore, instead of trying to merge them, we establish an API contract: Laravel exposes data via RESTful or GraphQL endpoints, and Next.js consumes those endpoints to render the UI. This approach aligns perfectly with modern application design principles, which is a key concept championed by the ecosystem surrounding Laravel.

Step-by-Step Integration Guide

Here is the practical workflow for setting up a decoupled Laravel/Next.js stack:

Phase 1: Setting Up the Laravel Backend (The API)

First, ensure your Laravel application is configured solely to serve data. This typically involves using Laravel to handle all CRUD operations and authentication.

  1. API Routes: Define clear API routes in routes/api.php. These routes will be responsible for fetching the necessary data that the frontend needs.
  2. Authentication: Implement token-based authentication, ideally using Laravel Sanctum. Sanctum is excellent for securing APIs between different domains (like your Next.js app and your Laravel backend).
// Example in routes/api.php
use App\Http\Controllers\DataController;

Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
    return $request->user();
});

Route::get('/products', [DataController::class, 'index']);

Phase 2: Setting Up the Next.js Frontend (The Client)

Next.js will be set up as a completely independent application that communicates with the Laravel API endpoints defined above.

  1. Initialize Next.js: Create your Next.js project using create-next-app.
  2. Data Fetching: Use Next.js data fetching methods (like getServerSideProps or client-side fetch) to make requests to your Laravel API endpoints.
  3. State Management: Manage the application state within Next.js, handling loading states and error responses gracefully when communicating with the backend.

Phase 3: Establishing Communication via Sanctum

The crucial link between these two applications is secure communication. By using Laravel Sanctum for token-based authentication, you ensure that only authenticated requests from your Next.js application can access sensitive data. This pattern allows developers to leverage the strengths of both ecosystems without forcing them into an unnatural monolith structure. As we see with robust frameworks like those on laravelcompany.com, separating concerns leads to more resilient systems.

Conclusion

To summarize, there is no single "Next.js preset" for Laravel because they serve different architectural purposes. The correct way forward is adopting a decoupled architecture: Laravel as the powerful data and business logic engine, and Next.js as the highly performant user interface layer. By focusing on API design and secure token-based communication (using tools like Sanctum), you achieve a clean, scalable, and modern full-stack application that benefits from the strengths of both PHP and JavaScript ecosystems.